Page 1 of 1

Extracting a part of a String

Posted: Tue Dec 16, 2008 12:42 am
by zerandib
Hello,

How to get a specific string from a variable

Like this;

There are 3 variables;

$var1 = "http://www.google.lk/setprefs?sig=[b]1_ ... lZSjtrMzck[/b]=abcdef&id=000001"
$var2 = "http://www.google.lk/setprefs?sig=[b]2_ ... WpWjtrMzck[/b]=abcdef&id=000001"
$var3 = "http://www.google.lk/setprefs?sig=[b]3_ ... lZSjtrMzck[/b]=abcdef&id=000001"


How to extract that bold letters from the above variables (var1,var2 and var3)
note that bold letters part is varied.
http://www.google.lk/setprefs?sig=<varied>=abcdef&id=000001
- red colored part are fixed.
So how to get the varied part of string (in blue) to a variable.

That is i want to get the string part between
http://www.google.lk/setprefs?sig= AND =abcdef&id=000001


need help
Thanks

Re: Extracting a part of a String

Posted: Tue Dec 16, 2008 12:48 am
by cavemaneca
With This the bold would be left.

Code: Select all

$string =  "http://www.google.lk/setprefs?sig=1_7I4o546645646ZZZZXXRRRKFNM9lZSjtrMzck=abcdef&id=000001";
$string = str_ireplace ('http://www.google.lk/setprefs?sig=','',$string);
$string = str_ireplace ('=abcdef&id=000001','',$string);
Also, don't post a new topic just because you don't get an answer you like.