Nandini Posted August 28, 2008 Share Posted August 28, 2008 i dont know about regular expresiion. So i need asistance. I have string like "username:password@host:port/username" OR "username:password:username@host:port/username" I want to split upto "username:password@host" if string is "username:password@host:port/username" OR I want to split upto "username:password:username@host" if string is "username:password:username@host:port/username" Here username,password,host and port values may be changed after every transaction. Can anyone help me. Link to comment https://forums.phpfreaks.com/topic/121662-split-string/ Share on other sites More sharing options...
effigy Posted August 28, 2008 Share Posted August 28, 2008 <pre> <?php $tests = array( 'username:password@host', 'username:password@host:port/username', 'username:password:username@host:port/username', ); foreach ($tests as $test) { echo "<b>$test</b><hr>"; $pieces = preg_split('%?=[^@]+\z)%', $test); print_r($pieces); } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/121662-split-string/#findComment-627883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.