Page 1 of 1
trim or concatenate in php
Posted: Tue Jan 13, 2009 11:53 am
by new2phpcode
Hi guys,
i have this value "201@61.11.235.228:5060=3Buser=3Dphone" how do i trim the value in php, removing everything after the "@"... Thank you!
Re: trim or concatenate in php
Posted: Tue Jan 13, 2009 11:56 am
by Mark Baker
new2phpcode wrote:i have this value "201@61.11.235.228:5060=3Buser=3Dphone" how do i trim the value in php, removing everything after the "@"...
Code: Select all
$string = "201@61.11.235.228:5060=3Buser=3Dphone";
$tmp = explode('@',$string);
$newString = $tmp[0];
Code: Select all
$string = "201@61.11.235.228:5060=3Buser=3Dphone";
list($newString) = sscanf($string,'%d@%s');
Re: trim or concatenate in php
Posted: Tue Jan 13, 2009 12:06 pm
by Apollo
or
Code: Select all
$string = preg_replace( '/@.*$/' , '' , $string );
Re: trim or concatenate in php
Posted: Tue Jan 13, 2009 12:36 pm
by new2phpcode
how about if i need to get the value in between "@" and ":"? sorry im kinda rusty on this....
Re: trim or concatenate in php
Posted: Tue Jan 13, 2009 12:42 pm
by Mark Baker
new2phpcode wrote:how about if i need to get the value in between "@" and ":"? sorry im kinda rusty on this....
Code: Select all
$string = "201@61.11.235.228:5060=3Buser=3Dphone";
$tmp = explode('@',$string);
$tmp = explode(':',$tmp[1]);
$newString = $tmp[0];
Code: Select all
$string = "201@61.11.235.228:5060=3Buser=3Dphone";
list($discard,$newString) = sscanf($string,'%d@%s:%s');
Re: trim or concatenate in php
Posted: Tue Jan 13, 2009 1:30 pm
by new2phpcode
Thank you.... i have made a solution with the explode....