Jump to content

Multiple str_replaces on a variable, in one command?


br3nn4n

Recommended Posts

I have this:

 

<?php
$article_raw=$_POST['article'];

$article = str_replace ( chr(10), "<BR>", $article_raw );
?>

 

Which takes my textarea's text and makes the carriage-returns into <BR>'s. Works perfectly :D

 

BUT--I'd like to be able to add pictures quickly by typing something like

 

[img:jvfb112507]

 

...and have it automatically replace that [img:jvfb112507] with something like

 

<div id="inline_photo"><img src="./images/articles/jvfb112507.jpg"></div>

 

I just have no idea how to do it ;) Any help is, as always, appreciated!

Oh brilliant! :D should've known php has it built in haha

 

Okay, I read the tizag.com tutorial on arrays and I think I'll try it out. Although, I still don't know how to tell it to find a string beginning with [img and use whatever value inside that to form the <div>

 

Sorry if I'm being a pain about this

$array = array('this','is','an','array','of','things','you','would','like','to','replace','with','null');

$string = "I like array's and things that you replace stuff with!";

foreach($array AS $boo){

$string = preg_replace("/$boo/is",NULL,$string);

}

echo $string;

# should return
# I 's d that stuff !

$array = array('this','is','an','array','of','things','you','would','like','to','replace','with','null');

$string = "I like array's and things that you replace stuff with!";

foreach($array AS $boo){

$string = preg_replace("/$boo/is",NULL,$string);

}

echo $string;

# should return
# I 's d that stuff !

 

i dont now if that sulotion solve your prob but here is a better way i guess lol

<?php 
$array = array('this','is','an','array','of','things','you','would','like','to','replace','with','null');
$string = "I like array's and things that you replace stuff with!";
$string = preg_replace("(".implode('|',$array)." )",NULL,$string);
echo $string;

# should return
# I 's d that stuff !
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.