Jump to content

explode with wildcards?


thefollower

Recommended Posts

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

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=".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.