Jump to content

[SOLVED] To cut a string with referance and get the location..


Recommended Posts

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....

 

 

 

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);
?>

 

 

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...

 

 

 

 

 

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);
?>

 

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..

 

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...

$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....

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.