natasha_thomas Posted May 2, 2010 Share Posted May 2, 2010 Friends, $this->aws["template"] = str_replace("%%Title%%", $this->aws["Title"], $this->aws["template"]); This is from my Amazon store API script, what does this code do? All i know is, i can use %%Title%% in my HTML template to output the Title. But i want to input this Title to a PHP variable, reason is, Title name has spaces, and i want to replace those spaces with "+", to make a SEO URl. - What does this code do? - How to pass the %%Title%% value to a PHP variable like, $title Can someone help? Thanks all Natty Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/ Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 It helps to understand the function str_replace. $title = $this->aws["Title"]; Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/#findComment-1051760 Share on other sites More sharing options...
natasha_thomas Posted May 7, 2010 Author Share Posted May 7, 2010 How Can i pass the Value of %%Title%%, to a PHP Vairbale? Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/#findComment-1054438 Share on other sites More sharing options...
anups Posted May 7, 2010 Share Posted May 7, 2010 Use urlencode function $this->aws["template"] = str_replace("%%Title%%", urlencode($this->aws["Title"])), $this->aws["template"]); Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/#findComment-1054440 Share on other sites More sharing options...
natasha_thomas Posted May 7, 2010 Author Share Posted May 7, 2010 $seotitle = str_replace("%%seotitle%%", str_replace(" ","-",$this->aws["Title"]), $this->aws["template"]); I just did this, does it make sense to anyone? Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/#findComment-1054445 Share on other sites More sharing options...
RichardRotterdam Posted May 7, 2010 Share Posted May 7, 2010 It helps to understand the function str_replace. $title = $this->aws["Title"]; In the link you can see how the str_replace function actually works How Can i pass the Value of %%Title%%, to a PHP Vairbale? From reading how the str_replace function works you will see that the first arguement is the search param which means it will search for %%Title%% and will replace it with the replacement. $this->aws["Title"] This is actually your title and not %%title%% Quote Link to comment https://forums.phpfreaks.com/topic/200423-what-this-single-line-code-does-and-how-pass-its-value-in-a-php-variable/#findComment-1054557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.