jnich05 Posted August 16, 2009 Share Posted August 16, 2009 I'm just starting to learn php and am trying to add a paramter $full_key_word into the string below. I'm wanting $full_key_word to replace "keyword" in the string. I've tried lots of things and I'm stumped. Any ideas? $rssFeeds = array( 0 => 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=keyword&ie=utf-8&num=10&output=rss', ); Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/ Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 <?php $rssFeeds = array( 0 => str_replace('q=keyword', 'q='.rawurlencode($full_key_word), 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=keyword&ie=utf-8&num=10&output=rss'), ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899289 Share on other sites More sharing options...
jnich05 Posted August 16, 2009 Author Share Posted August 16, 2009 It doesn't throw back errors like some of the stuff I've tried, but it still doesn't work. Is it possible that this new script is pulling a feed with $full_key_word in the url instead of processing that parameter and inserting whatever it produces? Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899298 Share on other sites More sharing options...
oni-kun Posted August 16, 2009 Share Posted August 16, 2009 Why not just replace the whole thing.. $keyword = foo; $rssFeeds[0] = 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q='.urencode($keyword).'&ie=utf-8&num=10&output=rss'; If the $rssFeeds variable does not require any extreme changes, place that after or in place of your old code.. and it'll change the keyword to what you set it as. $keyword could be set through $_GET if you wanted etc. Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899300 Share on other sites More sharing options...
asmith Posted August 16, 2009 Share Posted August 16, 2009 I don't know how you are trying this. How do you way it doesn't work? What do you do to see if it works or not? Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899302 Share on other sites More sharing options...
jnich05 Posted August 16, 2009 Author Share Posted August 16, 2009 The script is just a feed parser. It pulls data from an rss feed, but I'm trying to make it pull a different feed based on whatever words are made with $full_key_word. When I try running the new code you made, it just pulls back an empty feed which either means it's not working, or it's pulling back a feed for $full_key_word which there are no feed items for. Is it possibly pulling this: http://blogsearch.google.com/blogsearch_feeds?hl=en&as_drrb=q&as_qdr=d&q=$full_key_word&ie=utf-8&num=10&output=rss Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899307 Share on other sites More sharing options...
oni-kun Posted August 16, 2009 Share Posted August 16, 2009 My code works fine, I tested it myself! Go to these urls.. $keyword = WHATEVER $rssFeeds[0] = 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q='.urencode($keyword).'&ie=utf-8&num=10&output=rss'; http://blogsearch.google.com/blogsearch_feeds?hl=en&q=dog&ie=utf-8&num=10&output=rss http://blogsearch.google.com/blogsearch_feeds?hl=en&q=foo&ie=utf-8&num=10&output=rss http://blogsearch.google.com/blogsearch_feeds?hl=en&q=wow&ie=utf-8&num=10&output=rss They all work as rss, your parsing is done wrong then? What queries ARE returning something? Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899328 Share on other sites More sharing options...
jnich05 Posted August 17, 2009 Author Share Posted August 17, 2009 I think I've figured out a few more php tidbits this weekend trying to get this to work. It turns out they all worked, and I'm now using the code by asmith. I'm not sure how to explain why it didn't work at first, but it had something to do with not liking any parameters I was using in it. It worked perfectly when I used non-parameter words in the script, but eventually got it working by using a different parameter. Much thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170483-insert-a-parameter-into-a-string/#findComment-899855 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.