chanchelkumar Posted December 14, 2007 Share Posted December 14, 2007 Hi Friends, $check="front street Unique historical building Office Space - 1925 square foot + Call xxx-xxx-xxxx (18 Nov 2007) (xxx) xxxxxxx, - City Province Neighborhood Distance "; i want to get the city name to a variable, i tried it with explode("-",$check); but it give me the phone numer value as return.... Am having $phoneno:(xxx) xxxxxxx; i tried to strip with this... stristr($check,$phoneno); but returms me null Is there any function to cut the last five words (not letter), Please help me.... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 14, 2007 Share Posted December 14, 2007 you can try this for the <?php $check="front street Unique historical building Office Space - 1925 square foot + Call xxx-xxx-xxxx (18 Nov 2007) (xxx) xxxxxxx, - City Province Neighborhood Distance "; preg_match("/[\ ]+([\w\d]+)[\ ]+([\w\d]+)[\ ]+([\w\d]+)[\ ]+([\w\d]+)\ $/i",$check,$arrMatches); print_r($arrMatches); ?> Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 But rajiv .... I tried it with the example you provide... It works perfect... But my problem is my data ie $check is coming from database dynamically.... the format is same in last four cases...(City Province Neighborhood Distance), The format before that may differ... Sometimes that "-" replaces "$123" or "$123/month"... is there any idea for get that last four words... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 14, 2007 Share Posted December 14, 2007 you can with a strong regular expression similar to the one I provided if you can identify the different formats . Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 Am not used with regular expression, please let me know where i can find such a thing?? Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 Please help me.... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 14, 2007 Share Posted December 14, 2007 Ok try this <?php $check="front street Unique historical building Office Space - 1925 square foot + Call xxx-xxx-xxxx (18 Nov 2007) (xxx) xxxxxxx, - City Province Neighborhood Distance "; preg_match("/\)([^,]+)\,[\ \-]+([\w\d]+)[\ ]+([\w\d]+)[\ ]+([\w\d]+)[\ ]+([\w\d]+)\ $/i",$check,$arrMatches); print_r($arrMatches); ?> Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 Rajiv, Thanks... The new code is also working.... i want to cut the data in to two... Say the (City Province Neighborhood Distance) in to a string ... This will always come at the end... is any method for that? this will come after..("-" or "$123" or "$123/month").. I tried with explode ("-",$check)... But not working properly.. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 14, 2007 Share Posted December 14, 2007 oh I got it for the dash try $arrParts = preg_split("/\,[\ ]+\-/",$check); print_r($arrParts); Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 Thanks Rajiv... Little more help please... Now it's ok for dash("-")... How we can get it for ("$950 /") and ("$950 /month") ... 950 is any numerical value... thanks for your help... Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted December 14, 2007 Share Posted December 14, 2007 can you give me an example of the string with the $950 so I can test ? Quote Link to comment Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 $arrParts = preg_split("/\,[\ ]+\-/",$full_descript); $newck=$arrParts[1]; $newcheck=$arrParts[0]."</br>"; if ($newck!="") { $new_loc_final=$newck; } elseif ($newck=="") { $loca_new=explode("/ month",$newcheck); echo "</br>"."newlocation:: ".$loca_new[1]; $new_loc_final=$loca_new[1]; if ($loca_new[1]=="") { $loca_freshnew=explode("/ ",$newcheck); echo "</br>"."newlocationfresh:: ".$loca_freshnew[1]; $new_loc_final=$loca_freshnew[1]; } } $vowels = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "month","Month","MONTH"); $location_final= str_replace($vowels, "",$new_loc_final); echo "</br>"."FINAL LOCATION :".$location_final."</br>"; Thanks Rajiv... I done this with some complicate query... I am sure there is a simple way... Any way thanks alot... With your help i completed this.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.