sullyman Posted October 1, 2007 Share Posted October 1, 2007 Could you help me with one line please if you can. Looking for the answer online at the moment. I have my RSS working @ www.add.ie/rss.php but it's entering a Space instead of a Hypen (-) in the link title of each ad. I have tried sttr str replace etc. etc. How do i strip the spaces from v_title and replace them with a hypen. for ($i = 0; $i < mysql_num_rows($result1); $i++) { @$row = mysql_fetch_array($result1); $title = "".cleanText($row["v_title"]).""; $link = " http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; $description = cleanText($row["v_descr"]); Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/ Share on other sites More sharing options...
The Little Guy Posted October 1, 2007 Share Posted October 1, 2007 Try this: <?php for ($i = 0; $i < mysql_num_rows($result1); $i++) { @$row = mysql_fetch_array($result1); $title = preg_replace("~ ~","-",cleanText($row["v_title"])); $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; $description = cleanText($row["v_descr"]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359435 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 <?php $title= $_POST['v_title']; str_replace(' ', '-',$title)?> Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359437 Share on other sites More sharing options...
sullyman Posted October 1, 2007 Author Share Posted October 1, 2007 No Luck. First example stripped out all titles from RSS but still did not fix links. Second example stopped Rss.php loading Any other assistance would be great Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359441 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 $title = str_replace(' ','-',cleanText($row["v_title"])); Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359442 Share on other sites More sharing options...
The Little Guy Posted October 1, 2007 Share Posted October 1, 2007 Maybe this: <?php while($row = mysql_num_rows($result1)) { $title = cleanText(preg_replace("~ ~","-",$row["v_title"])); $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; $description = cleanText($row["v_descr"]); } ?> OR <?php while($row = mysql_num_rows($result1)) { $title = cleanText(str_replace(" ","-",$row["v_title"])); $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; $description = cleanText($row["v_descr"]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359446 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 both of those should work the clean text is just before instead of after Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359452 Share on other sites More sharing options...
sullyman Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks, The above code is changing the Title of each RSS Ad etc. but not affecting the link which is made up in the next line. $title = str_replace(' ','-',cleanText($row["v_title"])); But it is the following Line that the space needs to be subsituted with a hyphen $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; How do i leave Line 1 as it is and then Get Line 2 to strip Spaces from Link (Made up of v_title + Link_id in Line3) 1. $title = "".cleanText($row["v_title"]).""; 2. $title = str_replace(' ','-',cleanText($row["v_title"])); 3. $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359455 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 <?php $title = str_replace(' ','-',cleanText($row["v_title"]||$row["link_id"]));?> Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359458 Share on other sites More sharing options...
The Little Guy Posted October 1, 2007 Share Posted October 1, 2007 if this was placed into HTML form, How would you like it to look? Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359459 Share on other sites More sharing options...
sullyman Posted October 1, 2007 Author Share Posted October 1, 2007 Sorry Little guy, i'm at it all evening and it's wrecking me. Is this possible in line 2 to strip the spaces? $title = "".cleanText($row["v_title"]).""; $link = "http://www.add.ie/".str_replace(' ','-',cleanText($row["v_title"].cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359462 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 try my code it should strip out all spaces in link_id and title Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359467 Share on other sites More sharing options...
The Little Guy Posted October 1, 2007 Share Posted October 1, 2007 <?php for ($i = 0; $i < mysql_num_rows($result1); $i++) { @$row = mysql_fetch_array($result1); $title = preg_replace("~ ~","-",cleanText($row["v_title"])); $link = "http://www.add.ie/".preg_replace("~ ~","-",cleanText($row["v_title"]).cleanText($row["v_title"])."-0".cleanText($row["link_id"])).".html"; $description = cleanText($row["v_descr"]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359472 Share on other sites More sharing options...
sullyman Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks Dark freaks, But if i use that code, it is affecting the appearance of the title which i want to keep good in line 1. I need to incorporate the stripping process only in the second line below $title = "".cleanText($row["v_title"]).""; $link = "http://www.add.ie/".cleanText($row["v_title"])."-0".cleanText($row["link_id"]).".html"; Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359473 Share on other sites More sharing options...
sullyman Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks Little Guy, That worked. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359484 Share on other sites More sharing options...
darkfreaks Posted October 1, 2007 Share Posted October 1, 2007 topic solved dont forget to click it Quote Link to comment https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/#findComment-359487 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.