Skip to content
Advertisement

PHP get value from string

I am doing an intern atm and I faced a problem. Basically I have a string which is CN=van der Valk, Marco,OU=UT,OU=NL,OU=EMEA,OU=associates,OU=usersAndGroups,DC=corporate,DC=ingrammicro,DC=com but I only wasn’t what is after the CN which will be van der Valk in this case. I tried it with the trim function but didn’t succeed, can anybody help me?

Advertisement

Answer

You can use strpos.
First I find the position of CN= and then use that as the offset in the second strpos (to find the end of string).

JavaScript

https://3v4l.org/k5H26



I’m actually starting to think regex may be a good tool here.
Here I capture both firstname and lastname.
Then remove the slash and explode on comma and save them in $firstname and $lastname.
JavaScript

https://3v4l.org/9RN10

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement