Hi guys, this is my problem. I use wordpress and i have diffrent titles for every post. The php code for the title is <?php the_title(); ?> PHP: I want to add my title after this url: http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q= That means if i have a post with this title: php tutorials The url should be like this: http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q=php+tutorials This is the part of my php code that contains the url: <?php $url="http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q=php+tutorials"; $rss=new rssFeed($url); PHP: I tried this already but it is not working: <?php $url="http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q=<?php the_title(); ?>"; $rss=new rssFeed($url); PHP: Sorry, i hope you understand what i mean.
You can not have nested PHP tag. Whenever you start a PHP tag, you must close it (except if you are treating it as a literal): <?php $url="http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q=".the_title(); $rss=new rssFeed($url); PHP: The above should work assuming that the_title function returns the title and not print it out.
Thanks PHPMaster for your reply. I tried what you said. But it is not working. Is there any other solution? I also want to replace "spaces" with "+". That means if i have php tutorials as title the output should be like this: php+tutorials
try: $title=urlencode($post->post_title); $url="http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q=".$title;
Sorry for the late reply. First step, is you need to open the function the_title() (search for it). To be on the safe side (in the event that other places are using it). Change the function declaration to: // Change function the_title() // To function the_title($returnVar = false) PHP: Now look at the function itself, look for any echo's/print's and replace them with return if $returnVar is true. For example: // Change echo 'Site title'; // To if($returnVar){ return 'Site title';}else { echo 'Site title';} PHP: Now your code will look like: $title = str_replace(' ','+',the_title(true)); $url='http://search.msn.com/results.aspx?format=rss&FORM=RSRE&q='.$title; $rss=new rssFeed($url) PHP: Hope this helps.