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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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