Reply to change space to hyphen in sql query results

Your name:

Reply:


Posted by emmakane on 01/01/06 22:05

I am teaching myself PHP and am I am stuck trying to do the following.
I have the following code which pulls all the names of items in my
database and puts them in a hyperlinked list. I then want to be able to
click on a hyperling and use another script to search the database for
other instances of the item. The only trouble is the result $get[name]
in the url has spaces which are then ignored by the browser query.

<?
require "config.php"; // All database details will be
included here
$page_name="test.php"; //
$query="SELECT name FROM database1 ";
$result=mysql_query($query);
echo mysql_error();
while($get = mysql_fetch_array($result))
{
echo "<a
href=http://www.myurl.com/search.php?q=$get[name]&Search=Search>$get[name]<br>";

}
?>

I've been playing around with regex and also found the code below, but
I can't figure out how to implement either. Could someone tell me how
to do this?

Thanks,

Emma

<? php

function makeUrlFriendly($input) {
// Replace spaces with underscores
$output = preg_replace("/\s/e" , "_" , $input);

// Remove non-word characters
$output = preg_replace("/\W/e" , "" , $output);

return $output;
}

// Example useage:
echo makeUrlFriendly("I'm some really long title !!1"); // Gives:
Im_some_really_long_title_1
echo makeUrlFriendly("Weird chars too: ??? &amp;"); // Gives:
Weird_chars_too__amp

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация