Jump to content

Preg_match Help :@


tserfer

Recommended Posts

Hello,

 

I hate these preg_matches but this seems easy one

 

I have the following string

 

$string = "name=john; [email protected]; phone=4234234;";

 

I want to preg_match this $string to take our the keys name, email, phone and their values john, [email protected] and 4234234;

 

What is special about this is that the string may not contain the character ;  or it may have spaces between key and value. For example all the possible combinations are the followings.

 

$string = "name=john; [email protected]; phone=4234234;"; #primary

$string = "name=john; [email protected]; phone=4234234"; #it doesnt have for example the ; at the last one

$string = "name =john; email [email protected]; phone =4234234;"; #it has a space before the char =

$string = "name = john; email = [email protected]; phone = 4234234;"; #it has a space after and before the =

$string = "name= john;email= [email protected];phone=4234234;"; #it can be like that, no spaces everywhere

 

I hope you understand me.

Thank you

Link to comment
https://forums.phpfreaks.com/topic/279308-preg_match-help/
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.