Hello Guys, I have a problem here. Im using the following PHP code to retrieve data from my MySQL database. In the echo you can see the url to which the data is hyper-linked using the <a> tags. The {$row['tag']} is the main part of the URL. But it has spaces. How can i replace these spaces into hyphens. <?php $query = "SELECT tag FROM dle_search ORDER BY id DESC limit 0, 30"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='http://www.techspott.com/search/{$row['tag']}.html'>{$row['tag']}</a> | "; } ?> PHP: For example, the output looks like this: <a href="http://www.mydomain.com/search/Some Text Here.html">Some Text Here</a> I have already created an .htaccess file to redirect these to respective pages. If someone can help, i could replace these spaces with hyphens
<?php $query = "SELECT tag FROM dle_search ORDER BY id DESC limit 0, 30"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<a href='http://www.techspott.com/search/" . str_replace(' ', '-', $row['tag']) . ".html'>{$row['tag']}</a> | "; } ?> PHP:
Thanks Man! This Helped. A problem though! When i enter http://www.techspott.com/search/Google-Talk.html, the site searches for Google-Talk. Even though the URL is with a hypen, when it searches, it should search for Google Talk. Otherwise "no result found" error occurs.
You need to convert the - back to a space in the PHP before it is sent to the search function. str_replace('-', ' ', $someVariable); Can't give you any more than that without seeing the offending code.