Forum Moderators: coopster

Message Too Old, No Replies

Simple @preg match help required

Help with regex pattern in PHP

         

thinkdj

3:09 pm on Jan 7, 2008 (gmt 0)

10+ Year Member




The code goes something like :

.........
so.addParam("articleno", "itemID=389598&mediaURI=http://site.com/Files/%5BFile%20www.site.com%5D%20389598.2790557.11.htm
&postContentURL=http://site.com/Catalog_1.1.0.2.php&description=.......

I need to extract itemID and the URI

@preg_match('#"articleno", "itemID=([0-9]+)&mediaURI=(?)&postContentURL=#', $data, $matches);

What is the pattern that should come here?

Thanks a million in advance ..

mehh

4:06 pm on Jan 7, 2008 (gmt 0)

10+ Year Member



try:
[^\&]+

d40sithui

4:33 pm on Jan 7, 2008 (gmt 0)

10+ Year Member



i think this pattern might work for you


$str = "itemID=389598&mediaURI=http://site.com/Files/%5BFile%20www.site.com%5D%20389598.2790557.11.htm
&postContentURL=http://site.com/Catalog_1.1.0.2.php";
$pattern = "/(itemID=[0-9]+)¦(mediaURI=http:\/\/[a-zA-Z0-9]{3,}\.[a-zA-Z]{2,}[a-zA-Z0-9\.\_\-\/\%]+)/si";
preg_match_all($pattern, $str, $matches);
print_r($matches);

it would be a lot easier if you use split() or explode() if you just want to extract those vars.

$arr = explode("&", $str); // or $arr = split("&", $str);

thinkdj

6:12 pm on Jan 7, 2008 (gmt 0)

10+ Year Member



@mehh
[^\&]+ worked like a charm.. thanks dude

d40sithu
I am a n00b in PHP and as per your suggestion, finally checked out explode().. They beat regex method in this case.. Thanks dude