str_replace() isn't working

Ok, here's my problem:

$layout = $_POST["layout"];
$space = '"';
$mixed = $space . $layout . $space;

So in the form, $mixed would be $layout with quotes around. That isn't the problem.

$ttitle = '".$row["title"]."';
str_replace('TITLE' , $ttitle , $layout);

and when I type TITLE in the form, it just shows up "TITLE". What's happening?
LVL 1
spdaniel91Asked:
Who is Participating?
 
DarthModConnect With a Mentor Commented:
PAQd, 70 points refunded.

DarthMod
CS Moderator
0
 
RoonaanCommented:
You night need to use:

$layout = str_replace('TITLE' , $ttitle , $layout);

-r-
0
 
spdaniel91Author Commented:
but then, should it be

$layout = $_POST["layout"];
$layout = str_replace('TITLE' , $ttitle , $layout);
?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
RoonaanCommented:
Yes, that is correct.

-r-
0
 
system_downCommented:
isn't it a typo?

I mean $ttitle is correct? shouldn't be $title with only one t?

Let me know.

S_D
0
 
spdaniel91Author Commented:
No, $ttitle is table title. Just a name I thought of ;)
0
 
spdaniel91Author Commented:
And what about if I want 3 more str_replace?
0
 
RoonaanCommented:
You just add additional statements:

$layout = $_POST["layout"];
$layout = str_replace('TITLE' , $ttitle , $layout);
$layout = str_replace('TITLE2' , $ttitle2 , $layout);
$layout = str_replace('TITLE3' , $ttitle3 , $layout);
$layout = str_replace('TITLE4' , $ttitle4 , $layout);

-r-
0
 
RoonaanCommented:
Or you use an array:

$replacements = array(
  'TITLE' => $ttitle,
  'TITLE2' => $ttitle2,
  'TITLE3' => $ttitle2
);

$layout = $_POST["layout"];
$layout = str_replace(array_keys($replacements), $replacements, $layout);

-r-
0
 
spdaniel91Author Commented:
Sorry guys, I found another way. But none of yours was what I wanted, so sorry ;)
0
 
RoonaanCommented:
Hi,

What is the solution you chose to use?

-r-
0
 
spdaniel91Author Commented:

  /* Start replacing */
  $replace = array();
  $replace['title'] = str_replace("{TITLE}", $lrow['title'], $layout);   //Is the title
  $replace['date'] = str_replace("{DATE}", $lrow['date'] , $replace['title']); //Is the date
  $replace['main'] = str_replace("{MAIN}", $lrow['main'] , $replace['date']); //Is the content
  /* End replacing */

Yours was always with $layout in the end of str_replace(), but that echoed $layout 3 times.
0
 
RoonaanCommented:
No problems with PAQ-ing this question.
0
All Courses

From novice to tech pro — start learning today.