Click to See Complete Forum and Search --> : Parsing a string
AliBail
Nov 29th, 2002, 08:51 AM
How do I take text between two symbols, and do something with it, for example;
Taking these forums as an example, you can do [ url]http://www.alistairbaillie.co.uk[ /url]. (Without the sapces) and it automatically makes it a URL.
I know I could change the [ url] to <a href=" and the [ /url] to ">Click me</a>
but this doesn't give the same effect.
If anyone knows how I can achieve this, i would be gratefull.
Gimlin
Nov 29th, 2002, 02:49 PM
use str_replace()
http://www.php.net/manual/en/function.str-replace.php
DJ P@CkMaN
Nov 29th, 2002, 08:51 PM
You would however need a more advanced replace function such as ereg_replace() if you wanted [ url=www.blah.com]Text[ /url]
The Hobo
Nov 29th, 2002, 10:25 PM
Check out this thread (http://www.vbforums.com/showthread.php?s=&threadid=184356). Same concept.
da_silvy
Nov 30th, 2002, 06:59 PM
how about this code:
<?php
$searcharray = array("/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/esiU",
"/(\[)(url)(])([^\"]*)(\[\/url\])/esiU");
$replacearray = array("showurl('\\5', '\\7')",
"showurl('\\4', '\\4')");
$str = "hello.net (http://www.vbworld.com)<br>
http://www.vbworld.net";
echo $str."<br><br>";
$str=preg_replace($searcharray, $replacearray, $str);
echo $str;
function showurl($url, $hyperlink) {
return "<a href=\"$url\">$hyperlink</a>";
}
?>
That will handle [url] & [url=] without trouble.
Hope that's what you want :D
da_silvy
Nov 30th, 2002, 07:00 PM
that didn't post correctly..
quote it to get the actual code..
AliBail
Dec 1st, 2002, 02:34 PM
Originally posted by da_silvy
how about this code:
<?php
$searcharray = array("/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/esiU",
"/(\[)(url)(])([^\"]*)(\[\/url\])/esiU");
$replacearray = array("showurl('\\5', '\\7')",
"showurl('\\4', '\\4')");
$str = "hello.net (http://www.vbworld.com)<br>
http://www.vbworld.net";
echo $str."<br><br>";
$str=preg_replace($searcharray, $replacearray, $str);
echo $str;
function showurl($url, $hyperlink) {
return "<a href=\"$url\">$hyperlink</a>";
}
?>
That will handle [url] & [url=] without trouble.
Hope that's what you want :D
Thanks, thats exactly what i wanted :)
da_silvy
Dec 2nd, 2002, 12:04 AM
glad i could help :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.