Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.