Forum Moderators: phranque

Message Too Old, No Replies

PHP str replace question

url redirect

         

Ocean

3:46 am on Aug 24, 2009 (gmt 0)

10+ Year Member



<?
$query = "select * from TEST where type='board' order by no asc";
$rtt = mysql_query($query);
while($daa = mysql_fetch_array($rtt)){

$new_url = str_replace(" ", "-", $daa[id]);

?>

<a href="board/list.php?id=<?=$new_url?>" class=mm><?=$daa[id]?></a><br>

<?
}
?>

I have php script like that above.

The problem is str_replace replace space to dash but it becomes totally different page.

www.example.com/board/list.php?id=new%20url
www.example.com/board/list.php?id=new-url

I wonder the link actually goes to the first url and
url address shows second url?

I hope u understand..

If you have anotherway please let me know..

thanks

jdMorgan

3:02 pm on Aug 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This PHP code apparently takes URLs with a query string like "abc%20def" from the database, and puts a link on the page of <a href="board/list.php?id=abc-def">abc%20def</a>

So the link is to "board/list.php?id=abc-def" and the linked text on your page is abc%20def

It links to a hyphenated query string URL, but shows the 'name' of the link with a space in it.

Is this code something you added? If so, then you may need to add a similar code snippet in the routine that GETs the user-requested query string and looks up the 'next page' in your database. This code snippet would need to reverse the function done here, by changing the hyphens back to spaces so that the correct page can be found in your database.

Also, if you need detailed help with PHP, the contributors in our PHP forum can likely give you much better help than you'll find here in the Apache server configuration forum.

Jim

Ocean

6:59 pm on Aug 24, 2009 (gmt 0)

10+ Year Member



Thanks jdMorgan
Could you please give me the code?

or the link of the Apache server forum that I should look at

Thank you

jdMorgan

10:14 pm on Aug 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not a PHP coder. Try WebmasterWorld's PHP Server Side Scripting [webmasterworld.com] forum. :)

Jim

Ocean

4:14 am on Aug 31, 2009 (gmt 0)

10+ Year Member




System: The following message was spliced on to this thread from: http://www.webmasterworld.com/apache/3981005.htm [webmasterworld.com] by jdmorgan - 7:12 am on Aug. 31, 2009 (CT -5)



<?
$query = "select * from TEST where type='board' order by no asc";
$rtt = mysql_query($query);
while($daa = mysql_fetch_array($rtt)){

$new_url = str_replace(" ", "-", $daa[id]);

?>

<a href="board/list.php?id=<?=$new_url?>" class=mm><?=$daa[id]?></a><br>

<?
}
?>

I have php script like that above.

The problem is str_replace replace space to dash but it becomes totally different page.

www.example.com/board/list.php?id=new%20url
www.example.com/board/list.php?id=new-url

I wonder the link actually goes to the first url and
url address shows second url?

I hope u understand..

Please provide me a code. I have searched for couple weeks now but I still do not solve it..

thanks

jdMorgan

12:14 pm on Aug 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please review our Apache Forum Charter. We will be happy to answer specific questions and to help you get *your* code working, but we cannot provide a 'code-writing service' here.

Jim