Help With Preg_replace And Ereg_replace

Started on the old forum in August 2014 · view the original in the archive · old links redirect here

3 replies · 113 views · started 12 years ago · 1 min read

3 participants
adex3g Developer · 181 posts #1

$AOG_te = ereg_replace("http://[A-Za-z0-9./=?-_]+","<#>", $AOG_te); $AOG_te = preg_replace("/[url=(.?)](.?)[/url]/is","$2",$AOG_te); i have that above code in my bbcode function. But ereg_replace did not allow the preg_replace to work, what can i do so that two will work without affecting each other. If user post http:// coding-talk.com or [ url=http:// coding-talk.com]coding-talk should turn to link.

have connected with http://adexchat.com ? Fun up with http://forum.adexchat.com

Freddynic159 Junior · 43 posts #2

the problem arises when using double quotes. Try using single quotes. 👌

[NOTE]: function ereg_replace() is deprecated as of PHP 5.3.0.

$AOG_te = ereg_replace('http://[A-Za-z0-9./=?-_]+','<a href="$1">$2</a>',$AOG_te);
$AOG_te = preg_replace('/\[url\=(.*?)\](.*?)\[\/url\]/is','<a href="$1">$2</a>',$AOG_te);
itseasy21 Junior · 25 posts #4

Try this:

$URLSearchString = " a-zA-Z0-9\:\&\/\-\?\.\=\_\~\#\'";  
$AOG_te = preg_replace("(\[url\]([$URLSearchString]*)\[/url\])is", '<a href="$1">$1</a>', $AOG_te);
$AOG_te = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])is", '<a href="$1" >$2</a>', $AOG_te);

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close