Connecting Tech Pros Worldwide Forums | Help | Site Map

replacing in string

jc
Guest
 
Posts: n/a
#1: Dec 27 '05
Hi !

Could anyone help me to write a function which would chanfe the string like
this:

"content [foto 1 l] content content content content[foto 3 f] etc [foto 21
r]"
into
"content <img src="img/1.jpg class="l"> content content content content<img
src="img/3.jpg class="f"> etc <img src="img/21.jpg class="r">"

Big thanks,
jc



Janwillem Borleffs
Guest
 
Posts: n/a
#2: Dec 27 '05

re: replacing in string


jc wrote:[color=blue]
> Could anyone help me to write a function which would chanfe the
> string like this:
>
> "content [foto 1 l] content content content content[foto 3 f] etc
> [foto 21 r]"
> into
> "content <img src="img/1.jpg class="l"> content content content
> content<img src="img/3.jpg class="f"> etc <img src="img/21.jpg
> class="r">"[/color]

$content = preg_replace(
'/\[foto\s*(\d+)\s*([^]])\]/',
'<img src="img/$1.jpg class="$2">',
$content
);


JW


jc
Guest
 
Posts: n/a
#3: Dec 27 '05

re: replacing in string


"Janwillem Borleffs" <jw@jwscripts.com> wrote:
[color=blue]
> $content = preg_replace(
> '/\[foto\s*(\d+)\s*([^]])\]/',
> '<img src="img/$1.jpg class="$2">',
> $content
> );[/color]

Big thanks !
jc


Closed Thread