trim or concatenate in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

trim or concatenate in php

Post 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!
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: trim or concatenate in php

Post 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');
 
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: trim or concatenate in php

Post by Apollo »

or

Code: Select all

$string = preg_replace( '/@.*$/' , '' , $string );
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

Re: trim or concatenate in php

Post by new2phpcode »

how about if i need to get the value in between "@" and ":"? sorry im kinda rusty on this....
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: trim or concatenate in php

Post 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');
 
new2phpcode
Forum Newbie
Posts: 21
Joined: Tue Oct 09, 2007 10:40 pm

Re: trim or concatenate in php

Post by new2phpcode »

Thank you.... i have made a solution with the explode....
Post Reply