Jump to content

Write "str_replace" before it's in the link


spacepoet

Recommended Posts

Hello:

 

I wanted to see if someone knows how to do a "str_replace" before it's in the link ..

 

This is the code I currently have and it does work, but I want the "str_replace" to take place before it gets added to the link:

<?php

$query  = "SELECT product_id,myTitle FROM myProducts ORDER BY myTitle ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{				
$product_id = stripslashes($row['product_id']);
$myTitle = stripslashes($row['myTitle']);

?>

<li><a href="http://www.mywebsite.com/Promotional.Products-Promotional.Items/Promotional-Products/<?php echo $product_id ?>-<?php echo str_replace(" ", "-", $myTitle) ?>-<?php echo $full_state ?>-Promotional-Products.html" title="<?php echo $myTitle?> <?php echo "$full_state"; ?>"><?php echo $myTitle?></a></li>

<?php 
} 
?>

 

Is there anyway I can make it happen here"

$myTitle = stripslashes($row['myTitle']);

 

Everything I have tried has not worked ..

 

Ideas?

Just move the call to where you want it and save the result to a new variable, then put the variable in the link where the original call was.

 

$myTitle = stripslashes($row['myTitle']);
$myTitleDashed = str_replace(" ", "-", $myTitle);

 

<li><a href="http://www.mywebsite.com/Promotional.Products-Promotional.Items/Promotional-Products/<?php echo $product_id ?>-<?php echo $myTitleDashed; ?>-<?php echo $full_state ?>-Promotional-Products.html" title="<?php echo $myTitle?> <?php echo "$full_state"; ?>"><?php echo $myTitle?></a></li>

Hi:

 

Thank you -worked perfectly!

 

However, it did not solve my mod_rewrite issue (I thought it would).

 

Any idea why this:

#RewriteRule ^Promotional.Products-Promotional.Items/Promotional-Products/([0-9]+)-([a-zA-Z]+)-([a-zA-Z]+)-Promotional-Products.html$ Promotional.Products-Promotional.Items/Promotional-Products.php?product_id=$1&myTitleDashed=$2&full_state=$3

 

is not working? It keeps going to my 404 page.

 

 

It works fine when I am doing:

RewriteRule ^Promotional.Products-Promotional.Items/Promotional-Products/([0-9]+)-([a-zA-Z]+)-Promotional-Products.html$ Promotional.Products-Promotional.Items/Promotional-Products.php?product_id=$1&full_state=$2

<?php

$query  = "SELECT product_id,myTitle FROM myProducts ORDER BY myTitle ASC";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{				
$product_id = stripslashes($row['product_id']);
$myTitle = stripslashes($row['myTitle']);

?>

<li><a href="http://www.mywebsite.com/Promotional.Products-Promotional.Items/Promotional-Products/<?php echo $product_id ?>-<?php echo $full_state ?>-Promotional-Products.html" title="<?php echo $myTitle?> <?php echo "$full_state"; ?>"><?php echo $myTitle?></a></li>

<?php 
} 
?>

 

But when I add the product to it, it keeps failing. It has something to do with the spaces in the product name, because when there is a product with a single word, it goes to the page fine.

 

I thought if I replaced the spaces with hyphens, it would match and I would not have any errors.

 

Any ideas??

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.