Okay, in my database, one of the fields will contain information that looks like:

p.php?o=111, p.php?o=222, i.php?o=233, i.php?o=999, p.php?o=444, g.php?o=765

And after my query, I want to create an array based on this field, but I only want the items that start with "i.php..." in the array.

Not only do the numbers after the "=" sign change, but the "p.php" parts change too, so I won't know exactly what the values in this field will be. I looked into functions like eregi_replace, but it seems like I need to know what I'm replacing before it's being replaced.

I also looked into making the array first and then trying functions like array_slice, array_search, and array_filter, but I'm running into the same problem.

Can someone help me out here?

    i'm not sure i understand... it sounded like you only wanted those pieces of the string that start with "i.php", but then you brought up "p.php" again, so i'm a little confused. if all you want is all the strings between the commas that start with the "i.php?", then, you could try this and see if it does what you're after:

    $String = 'p.php?o=111, p.php?o=222, i.php?o=233, i.php?o=999, p.php?o=444, g.php?o=765';
    preg_match_all('|i\.php\?.+?(?=,)|i', $String, $match);
    foreach ($match[0] as $x)
    	echo "$x<br />\n";
    

      My question is: how did you end up with a database field that contained stuff like that?!

        Write a Reply...