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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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 !

Link to comment
Share on other sites

$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 !
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.