Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I get X (or another value) from this string "asdfsadf[www]X[/www]"

Michael
Guest
 
Posts: n/a
#1: Dec 20 '05
How can I get X (or another value) from this string
"asdfsadf[www]X[/www]",
basically i want to get what ever is in between the [www] tags and
place them in a variable called $www , can anyone help?


Scot McConnaughay
Guest
 
Posts: n/a
#2: Dec 20 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


You could probably use the strrpos($string, "[www]") to get the position
of the "X" data. Then use the substr($string, $position_start,
$position_end) function to create your $www variable...

Let me know if that doesn't help.

also, check these pages out :)

http://us2.php.net/manual/en/function.substr.php
http://us2.php.net/manual/en/function.strrpos.php

Michael wrote:[color=blue]
> How can I get X (or another value) from this string
> "asdfsadf[www]X[/www]",
> basically i want to get what ever is in between the [www] tags and
> place them in a variable called $www , can anyone help?
>[/color]
Michael
Guest
 
Posts: n/a
#3: Dec 20 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


Thanks, this looks like it will work fine, I don't have time to try it
now but I will have a look at it later. I would be interested to know
if there is a simpler way to do it though.

cyberhorse
Guest
 
Posts: n/a
#4: Dec 22 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


a less efficient, but perhaps easier to read or more flexible method
would be something like:
ereg('\[www\](.*)\[/www\]', $text, $arr);
$variable_inside_www = $arr[1];

Michael
Guest
 
Posts: n/a
#5: Dec 22 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


I need a solution that will loop until all of the [www][/www] tags in
string into an array and from there on i have everything sorted.

Mara Guida
Guest
 
Posts: n/a
#6: Dec 22 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


Michael wrote:[color=blue]
> I need a solution that will loop until all of the [www][/www] tags in
> string into an array and from there on i have everything sorted.[/color]

If you want to go the regular expression way, have a look at
preg_match_all().

If you want to go the strpos(), substr() way, remember the third
parameter to the strpos() function.

cyberhorse
Guest
 
Posts: n/a
#7: Dec 23 '05

re: How can I get X (or another value) from this string "asdfsadf[www]X[/www]"


with ereg, you can do something similar to this:

while (ereg('\[www\](.*)\[/www\](.*)', $text, $arr))
{
$variables_inside_www[] = $arr[1];
$text = $arr[2];
}

Closed Thread