kadamsurekha Posted June 16, 2007 Share Posted June 16, 2007 hello! i hav a string which will be like "abcd*pqrs*" i want the "abcd" part to store separetely in 1 string and "pqrs" separetely. i have written the code as follows: <? $friendname=$_get["user"];//this will store tht strng (abcd*pqrs*) $x=0; for($i=0;$i<strlen($friendname);$i++) { if($friendname[$i]=='*') { $str=substr($friendname,$x,$i-1); echo "$str"; $x=$i+1; } } ?> can any1 tell me what is wrong here?? or any other way to do it? Quote Link to comment https://forums.phpfreaks.com/topic/55827-string-in-php/ Share on other sites More sharing options...
taith Posted June 16, 2007 Share Posted June 16, 2007 its much faster/easier this way... $friendname=$_get["user"]; $explode=explode('*',$friendname); //then you have part one in $explode[0] and part 2 in $explode[1]... and so on :-) Quote Link to comment https://forums.phpfreaks.com/topic/55827-string-in-php/#findComment-275772 Share on other sites More sharing options...
sasa Posted June 16, 2007 Share Posted June 16, 2007 or <?php $a ='*sasa*dfg*jkl*55555*6666'; preg_match_all('/\*([^\*]+)/',$a, $b); print_r($b[1]); ?> Quote Link to comment https://forums.phpfreaks.com/topic/55827-string-in-php/#findComment-275866 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.