Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

str_replace() isn't working

Posted on 2006-11-18
14
Medium Priority
?
220 Views
Last Modified: 2008-03-06
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?
0
Comment
Question by:spdaniel91
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 17971623
You night need to use:

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

-r-
0
 
LVL 1

Author Comment

by:spdaniel91
ID: 17971635
but then, should it be

$layout = $_POST["layout"];
$layout = str_replace('TITLE' , $ttitle , $layout);
?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17971647
Yes, that is correct.

-r-
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:system_down
ID: 17971928
isn't it a typo?

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

Let me know.

S_D
0
 
LVL 1

Author Comment

by:spdaniel91
ID: 17972048
No, $ttitle is table title. Just a name I thought of ;)
0
 
LVL 1

Author Comment

by:spdaniel91
ID: 17972054
And what about if I want 3 more str_replace?
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17972058
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
 
LVL 49

Expert Comment

by:Roonaan
ID: 17972062
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
 
LVL 1

Author Comment

by:spdaniel91
ID: 17972845
Sorry guys, I found another way. But none of yours was what I wanted, so sorry ;)
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 17973962
Hi,

What is the solution you chose to use?

-r-
0
 
LVL 1

Author Comment

by:spdaniel91
ID: 17974539

  /* 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
 
LVL 49

Expert Comment

by:Roonaan
ID: 17993996
No problems with PAQ-ing this question.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 18024955
PAQd, 70 points refunded.

DarthMod
CS Moderator
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question