Solved

str_replace() isn't working

Posted on 2006-11-18
14
213 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
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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now