Jump to content

[SOLVED] strpos effectiveness


Ninjakreborn

Recommended Posts

Is strpos() as affective as straight regular expressions for finding a basic string inside another string.

For example, validating filetypes (Other filetypes).

Say I wanted to allow only .mov, Is strpos checking for mov inside a filetype going to be safe, or testing for .mov.  Is this going to be as affective as setting it up to test with regular expressions?

Link to comment
Share on other sites

If you're checking for a string at the end of another string, regular expressions will be slightly easier on the eyes because you can use the \z anchor. If you use strpos, you'll need to calculate the results against both lengths to determine that it is, in fact, at the end.

Link to comment
Share on other sites

I know, but I am running it through an array.  I wanted to know if it's 100% safe.

I want to run it through something like.

 

$extensions = array(".wav",

                          ".mov",

                          ".swf"); // plus whatever else will be here

 

foreach ($extensions as $k => $v) {

  if (strpos($extensions, $file)) {

    req

 

 

}

ah whatever I will get it together when I get started, but that's the basic idea.  I am going to use strpos to validate the filetype's.

Link to comment
Share on other sites

If you're checking for a string at the end of another string, regular expressions will be slightly easier on the eyes because you can use the \z anchor. If you use strpos, you'll need to calculate the results against both length's to determine that it is, in fact, at the end.

I am just frustrated because I had an entire file handling system created I recopied, however accidentally deleted the source file's along time ago, and haven't gotten around to building another one.  This project is going to require me to rebuild another one, which I am looking for quicker way's to get this up and running.  I may just use regular expressions.

 

Thanks for all the advice.

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.