webready Posted September 23, 2010 Share Posted September 23, 2010 Hello All, I'm using php to auto-insert variables into a canonical url within the <head>. Here is my code: <link rel="canonical" href="http://www.mysite.com/page.php?IT=<?php print $item; ?>&IT2=<?php print $desc; ?>" /> I used this to replace "+" with " ". <?php $desc = str_replace ("+"," ",$desc); ?> The problem is i use the variables in different sections of the page were I don't want the "+" to appear. I only want the "+" to appear in the canonical url space. I'm sure there is an easy way, but not for me So to sum up: I want srt_replace code to be incorporated into the <?php print $desc; ?> code ONLY. Thanks in advance for any help! Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 and what if you echo it out like <?php echo str_replace ("+"," ",$desc);?> That way you don't have to change the variable but only change the output of the variable like: <?php $desc = 'lalalalaal + laalalala + lalalalala +'; echo str_replace ("+"," ",$desc); ?> Quote Link to comment Share on other sites More sharing options...
webready Posted September 23, 2010 Author Share Posted September 23, 2010 Hi Fortnox007, Thanks for the reply. Unfortunately I'm even more confused. Anyway to incorporate the str_replace ("+"," ",$desc); RIGHT INTO <link rel="canonical" href="http://www.mysite.com/page.php?IT=<?php print $item; ?>&IT2=<?php print $desc; ?>" /> like <?php echo $desc; "NEW STR CODE GOES HERE"?> Thanks again! Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 hehe np, i just make it more clear (i hope ) <link rel="canonical" href="http://www.mysite.com/page.php?IT=<?php print $item; ?>&IT2=<?php echo str_replace ("+"," ",$desc); ?>" /> So just like i showed you I echo str_replace instead of assigning $desc again. to explain that in more detail: if you do this $desc = str_replace ("+"," ",$desc); // here you are assiging $desc , and thus altering it's value but if you do this: echo str_replace ("+"," ",$desc); // you are just outputing the value of $desc, //but altering the output via str_replace instead //of altering $desc, that way it keeps it's value to be used below like you wanted Quote Link to comment Share on other sites More sharing options...
webready Posted September 23, 2010 Author Share Posted September 23, 2010 WOW, thank you so much, I believe it worked!!! Can't thank you enough. I don't want to mark as "solved" yet as I want to go live with it to completely verify. Thank you again! Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 As long as you do it when it's live haha Btw you can do this with all functions. like: $desc = 'I am a string'; echo strtoupper($desc); echo strtolower($desc); Quote Link to comment Share on other sites More sharing options...
webready Posted September 23, 2010 Author Share Posted September 23, 2010 Ok, I knew there would be something else In some case I actually use "%2D" in my URL's were I want the. The "%2D" stays in the URL address bar. But, in the canonical URL, it shows a "+". Anyway to make sure the canonical version prints the "%2D" and not the decoded "+". I know, I'm crazy! Thanks again Quote Link to comment Share on other sites More sharing options...
webready Posted September 23, 2010 Author Share Posted September 23, 2010 Continued.... Basically I want the URL in the address bar to match the URL in the canonical. Thanks Again! Quote Link to comment Share on other sites More sharing options...
webready Posted September 23, 2010 Author Share Posted September 23, 2010 I'm sorry, I meant "%2B" Quote Link to comment Share on other sites More sharing options...
fortnox007 Posted September 23, 2010 Share Posted September 23, 2010 lol I totally lost track of you Quote Link to comment 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.