|
-
Nov 29th, 2002, 09:51 AM
#1
Thread Starter
Hyperactive Member
Parsing a string
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.
-
Nov 29th, 2002, 03:49 PM
#2
Fanatic Member
-
Nov 29th, 2002, 09:51 PM
#3
Lively Member
You would however need a more advanced replace function such as ereg_replace() if you wanted [ url=www.blah.com]Text[ /url]
There's something I've noticed in the last year or so...
Australian's are good at EVERYTHING !!!
-
Nov 29th, 2002, 11:25 PM
#4
Stuck in the 80s
Check out this thread. Same concept.
-
Nov 30th, 2002, 07:59 PM
#5
Conquistador
how about this code:
Code:
<?php
$searcharray = array("/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/esiU",
"/(\[)(url)(])([^\"]*)(\[\/url\])/esiU");
$replacearray = array("showurl('\\5', '\\7')",
"showurl('\\4', '\\4')");
$str = "hello.net<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
-
Nov 30th, 2002, 08:00 PM
#6
Conquistador
that didn't post correctly..
quote it to get the actual code..
-
Dec 1st, 2002, 03:34 PM
#7
Thread Starter
Hyperactive Member
Originally posted by da_silvy
how about this code:
Code:
<?php
$searcharray = array("/(\[)(url)(=)(['\"]?)([^\"']*)(\\4])(.*)(\[\/url\])/esiU",
"/(\[)(url)(])([^\"]*)(\[\/url\])/esiU");
$replacearray = array("showurl('\\5', '\\7')",
"showurl('\\4', '\\4')");
$str = "hello.net<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
Thanks, thats exactly what i wanted
-
Dec 2nd, 2002, 01:04 AM
#8
Conquistador
glad i could help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|