Solved

str_replace() isn't working

Posted on 2006-11-18
14
218 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

624 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