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.... Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414675 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... Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414678 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 . Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414681 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?? Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414688 Share on other sites More sharing options...
chanchelkumar Posted December 14, 2007 Author Share Posted December 14, 2007 Please help me.... Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414707 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); ?> Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414711 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.. Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414723 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); Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414724 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... Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414755 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 ? Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414760 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.... Link to comment https://forums.phpfreaks.com/topic/81632-solved-to-cut-a-string-with-referance-and-get-the-location/#findComment-414792 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.