thefollower Posted January 6, 2010 Share Posted January 6, 2010 Hey, Is there a way to explode a string which would have a fixed first half then a wildcard second half... for example say i have: www.domain.com?id=12345678 www.domain.com?id=87654321 Notice i got the domain the same but ID is different but say a user inputs it like this: www.domain.com?id=12345678www.domain.com?id=87654321 or www.domain.com?id=12345678,www.domain.com?id=87654321 or www.domain.com?id=12345678 www.domain.com?id=87654321 Any one of the above inputs could occur from a user But because i know the the id has 8 chars i want to explode it so i can get each link and put them in an array regardless of the format they are inputted. Link to comment https://forums.phpfreaks.com/topic/187465-explode-with-wildcards/ Share on other sites More sharing options...
zq29 Posted January 6, 2010 Share Posted January 6, 2010 As far as I'm aware, you can't do this with explode(). However, you might want to look into RegularExpressions, and preg_match_all(). <?php //Untested... $str = "www.domain.com?id=12345678,www.domain.com?id=87654321"; preg_match_all('~id=([0-9]{8})~is',$str,$m); echo "<pre>",print_r($m),"</pre>"; ?> This would echo out all of the 8 digit strings that appear after an "id=". Link to comment https://forums.phpfreaks.com/topic/187465-explode-with-wildcards/#findComment-989872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.