Solved

Check string matches pattern

Posted on 2004-03-26
9
349 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...
0
Comment
Question by:edwinbrains
  • 4
  • 3
  • 2
9 Comments
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10689851

did you try recode_string()?

check the link for other details...

http://www.php.net/manual/en/function.recode-string.php
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10689883
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
0
 

Author Comment

by:edwinbrains
ID: 10689953
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 :-)
0
 

Author Comment

by:edwinbrains
ID: 10693862
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...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:JtR
ID: 10694497
yeah, you need to build an regulary expression for this! (using eregi()-function to check!)
0
 

Author Comment

by:edwinbrains
ID: 10694966
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.
0
 
LVL 3

Accepted Solution

by:
JtR earned 100 total points
ID: 10695409
if ( eregi( "^([A-Za-z0-9=/]*)$", $str ) )
echo "is Base64";
else echo "is not Base64";
0
 
LVL 3

Expert Comment

by:JtR
ID: 10695411
this should match any of the combination you told! $str is the string you want to check!
0
 

Author Comment

by:edwinbrains
ID: 10695623
That's exactly what I wanted - thanks :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Form Processing in PHP 11 30
How do I put a session for a radio button? 4 12
is this a cms? 8 32
Website Interactive tool that will do calculations 3 23
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now