Jump to content

[SOLVED] Strip Spaces and change to Hyphen


sullyman

Recommended Posts

 

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"]);

Link to comment
https://forums.phpfreaks.com/topic/71413-solved-strip-spaces-and-change-to-hyphen/
Share on other sites

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"]);
}
?>

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"]);
}
?>

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

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";

<?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"]);
}
?>

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";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.