Good day
I got this string that I want to break into different smaller strings
For example
I want to add this to a drop down select menu
Column B|b1|b2|b3|b4|b5|
Where the | represents the end of an element
So, how do I break each part off and add them as options?
Break a string into multiple strings
Moderator: General Moderators
Re: Break a string into multiple strings
Ah, much love buddy.
Re: Break a string into multiple strings
Are you reading this from a file? Because fgetcsv will both read and split the line.
Re: Break a string into multiple strings
Nah, reading it from an excel file at the moment but I gotta add in some CSV functionality later so thats gonna help
Re: Break a string into multiple strings
From php.net http://us2.php.net/manual/en/function.explode.php
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
?>
The above example will output:
Array
(
[0] => one
[1] => two|three|four
)
Array
(
[0] => one
[1] => two
[2] => three
)
Hope this helps.
Matthew Vass
QA Analyst
mvass@hostmysite.com
http://www.hostmysite.com?utm_source=bb
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
?>
The above example will output:
Array
(
[0] => one
[1] => two|three|four
)
Array
(
[0] => one
[1] => two
[2] => three
)
Hope this helps.
Matthew Vass
QA Analyst
mvass@hostmysite.com
http://www.hostmysite.com?utm_source=bb