Jump to content

split string


Nandini

Recommended Posts

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

<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

Archived

This topic is now archived and is closed to further replies.

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