We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Check string matches pattern

edwinbrains
edwinbrains asked
on
Medium Priority
413 Views
Last Modified: 2008-02-01
Hi everyone,

Basically, I want to check if a string is base64 encoded. If you can think of a good way to do this (other than the way I'm about to suggest), please tell me!

I think I want to check if the string contains only letters of the alphatbet (both uppercase and lowercase), numbers, equal signs (=) forward slashes (/) and no spaces. If the string is like this, I'm going to treat it as base64 encoded.

I've no idea how I would check a string for this. I suppose I would use preg_match or ereg or some other simliar function, but learning all that syntax is just too complicated. Would someone give me a function I could use?

Many thanks in advance...
Comment
Watch Question


did you try recode_string()?

check the link for other details...

http://www.php.net/manual/en/function.recode-string.php
recode() is also same....
I dont know, but it seems there are bugs with recode()..try iconv()

http://www.php.net/manual/en/ref.iconv.php

Author

Commented:
After enabling the iconv extension in php.ini (I got call to undefined function), my page wouldn't refresh using the recode_string or recode functions. It just took forever loading.

I would look at the iconv function but I went to that php.net page, and I really don't have a clue what it's going on about. I'm a bit confused about the recode function too.

Please bare with me, this is new stuff for me :-)

Author

Commented:
Any ideas on how I can determine if a string only contains letters of the alphatbet (both uppercase and lowercase), numbers, equal signs (=) forward slashes (/) and no spaces? Please guys...
JtR

Commented:
yeah, you need to build an regulary expression for this! (using eregi()-function to check!)

Author

Commented:
Yeah, but can someone tell me exactly how to use it? I have no idea what pattern to use, and it looks too daunting to learn.
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
JtR

Commented:
this should match any of the combination you told! $str is the string you want to check!

Author

Commented:
That's exactly what I wanted - thanks :-)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.