Exploding a string snippet
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
How does one 'chop up' a field you ask?
For instance, taking a field with "2.34x3.29x4.20" (let's call it field_sizes), cutting the x's out, and separating the values.
<?php
$my_field = trim($node->sizes[0]['value'],"x");
$values = array();
$my_measures = explode("x", $my_field);
$my_delta = 0;
foreach ($my_measures as $my_measure) {
$node_field[$my_delta]['value'] = trim($my_measure);
$my_delta++;
}
?>
and in the display format:
$display = $node_field_item['value'];
This takes field_sizes (1.12x9.32x2.12), and choppes (explodes..) it into a field with 3 values (1.12 , 9.32 , 2.12).
Enjoy!
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion