PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I've got a little problem with string -> array.
I have a string and I want that some parts of it becomes an array, in the string there are keywords it should react to.
Example:
I'm not sure if there's some magical combination of built-in functions to do this. My first solution would be to search the string for <tis>, and remove everything up to and including the tag. Then, search the remainder for </tis>. Put everything in the newly cropped string up to the beginning of the </tis> tag into the array, remove the </tis> tag, then continue.
$string = weeee<tis>Into array 1</tis>someandomtext<tis>Into array 2</tis>morerandomtext<tis>Into array 3</tis>andsomemore
while(<tis> is found in $string)
{
$position = position of <tis> in $string;
$string = everything after $position + 5
if(</tis> is found in string)
{
$position = position of </tis> string;
$array[] = everything from beginning of $string to $position
$string = everything after $position + 6
}
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
If I'm understanding what you want correctly, this sounds like very nearly a job for the 'explode' function, except that you have two distinct delimiters <tis> and </tis>. It might even work to replace </tis> with <tis> then use explode...plus a little coding allowance for overhangs...