Welcome Guest, Not a member yet? Register   Sign In
Ereg replace.
#1

[eluser]Young Caveman[/eluser]
Hi. :-)
I looked for this on the web but there was not anything which I can understand Wink
I have to use ereg_replace function in my app, but ereg syntax is very hard to understand. You all can try to explain me with simple words? Big Grin Thank you.

Ps. Just to inform you: i have to replace every string which looks like this: "-" anthing "-" to: "<div>anything</div>".

Then
Code:
-hello-
would become
Code:
<div>hello</div>

I apologize but I never used this function and it's a bit complicated Big Grin
Thanks in advance.

Don ~ Albé
#2

[eluser]xwero[/eluser]
Code:
preg_replace('/-(.?)-/','<div>$1</div>',$str);
#3

[eluser]Sam Dark[/eluser]
Code:
$str = preg_replace('~-([^-]+)-~', '<div>$1</div>', $str);

or

Code:
$str = preg_replace('~-(.+?)-~', '<div>$1</div>', $str);
#4

[eluser]Young Caveman[/eluser]
Thank you. :-)




Theme © iAndrew 2016 - Forum software by © MyBB