Jump to content

Preg_Replace (Space to dash)


hitk

Recommended Posts

Ok. I have ZERO PHP Knowledge, still good in editing php and all that stuff. Only know copy paste and have no knowledge what that means. Still would try to explain my problem.

 

I use variable to fetch data from mysql. Ex. my url is http://www.example.com/venue.php?vcity=New York.

 

Now, I want to replace New York with New-York. The real url I am trying to get is http://www.example.com/venue-new-york.php.

 

For that I added code in htaccess

RewriteRule ^venue-([^/]*)\.php$ /venue.php?vcity=$1 [L]

 

I Know what I added in htaccess is mostly perfect.

 

Now, I am using smarty so would be able to do lower case and replace space with dash. But that would not allow me to fetch data from mysql for some reason. In class file I have following code.

 

 

function getallvenueschedule()
{
	global $db,$smarty;
	$sql = " SELECT * FROM table WHERE vcity = '$this->vcity' AND sch_date >= '$this->sch_date' ORDER BY timestmp ASC";
	$theList	= $db->getAll($sql); 
	return $theList;
}

 

In the php file below is code.

 

 

$vcity = $_GET['vcity'];

 

I hope I provided almost all details. Problem is that whatever data is in variable vcity (examp. if I have new-york in url then it will search new-york in mysql rather new york

Link to comment
https://forums.phpfreaks.com/topic/207098-preg_replace-space-to-dash/
Share on other sites

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.