$sss = '[pagetitle]'; $ss = str_replace("_", " ", $sss); echo $ss; PHP: it sees it,but wont replace the underscores. $sss = "some_thing"; it will. it shouldn't matter since [pagetitle] passed from $sss to $ss :confused: PHP:
I dont really get what you want to do... if $sss contains varible '[pagetitle]' its cant replace _ becuse '[pagetitle]' dont have it... str_replace replace only values that inside the value you looking for try to do this $var = '[pagetitle]'; $var2 = str_replace( "_", " ", $var, $count); print "var1: $var\n var2: $var2\n count of replaces: $count"; exit(); PHP: it will show you the number of times the str_replace find and replace your searched value. hope it'll help ya
as a good rule of thumb echo out $sss to see what it contains. Then you know if it contain illegal charactors. else{it wont work}
[pagetitle] is the function that pulls some_thing from the database. my code works,but it doesn't remove the underscore from some_thing. if i replace $sss = '[pagetitle]'; with $sss = "some_thing"; it removes the underscore.
I think it is still a grave mystery to everyone what you are talking about. Is [pagetitle] supposed to be some sort of placeholder for an actual function call, for the purposes of this forum post? If so, putting quotes around it is a very confusing way to present it to us. Why don't you echo $sss immediately prior to the str_replace() call to see if it really contains what you thought it did?
$sss = '[pagetitle]'; $find = "_"; if (strpos($sss, $find) === FALSE) { var_dump($sss); } else str_replace("_", " ", $sss); PHP: Try this, should help debugging.
before <h2>[pagetitle]</h2> PHP: after <? $sss = '[pagetitle]'; $ss = str_replace("_", " ", $sss); ?> <h2><?php echo $ss; ?></h2> PHP: exact coding. both work the same,but the second one doesn't remove the underscore. i'm not sure where the pagetitle is pulled from the functions. [pagetitle] is like an echo,so i don't get why it doesn't replace the underscores,unless it has to be on the $ in the functions.
I don't know what you think square brackets do, but I can assure you they don't do it. Maybe you are thinking of {curly brackets}? $sss = '[pagetitle']; has exactly one effect: that is, it puts the characters [ p a g e t i t l e ] in the variable $sss. Nothing else. Your str_replace will never do anything because there is no underscore in that string ("[pagetitle]").
Okay. Well, firstly I'm going to assume you use a templating class to parse the file (and hence fill [pagetitle] with data that DOES include underscores.) Please post this templating script. If you do NOT use a templating script, WHICH UNDERSCORE?
If that is your "before" and "after", I'd go with the "before", as the "after" is just a waste of PHP. The code that you just gave is going to take the string "[pagetitle]" and replace the underscores with spaces, doing absolutely nothing in the process. There must be something that I am missing, because there is no point in removing underscores from a string that you physically coded into a variable yourself, anyways. I am really trying to figure out what is going on here. If you are thinking that '[pagetitle]' is going to do something magical and produce you some underscores, taking the single-quotes off of it would help. But that's not even the case. Good luck with your code.