Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

24 views
Skip to first unread message

Michael

unread,
Dec 20, 2005, 11:00:45 AM12/20/05
to
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

unread,
Dec 20, 2005, 11:27:37 AM12/20/05
to
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

unread,
Dec 20, 2005, 12:31:14 PM12/20/05
to
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

unread,
Dec 21, 2005, 7:06:57 PM12/21/05
to
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

unread,
Dec 22, 2005, 5:58:39 AM12/22/05
to
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

unread,
Dec 22, 2005, 6:36:49 AM12/22/05
to
Michael wrote:
> 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.

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

unread,
Dec 23, 2005, 9:23:33 AM12/23/05
to
with ereg, you can do something similar to this:

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

0 new messages