Jump to content

[SOLVED] getting part of a string


cha0sriderx

Recommended Posts

<?php
$image="new.gif";
if (exif_imagetype($image) == IMAGETYPE_GIF) {
    echo 'The picture is a gif';
}
elseif(exif_imagetype($image) == IMAGETYPE_JPEG) {
    echo 'The picture is a jpeg';
}
elseif(exif_imagetype($image) == IMAGETYPE_PNG) {
    echo 'The picture is a png';
}
else
{
echo "Image type unknown";
}

?>

 

This is just an example.

You can use case statements to be more appropriate.

 

Link to comment
Share on other sites

If all you want is the extension of the file:

<?php
  $file = "some.file.txt";
  $tArr = explode(".", $file);
  $ext = $tArr[count($tArr) - 1];

  $new_name = rand(5, 10) . $ext;
  echo $file . "<br>" . $new_name . "<br>";
?>

 

Bear in mind however, that the extension of the file has no bearing on the type of file.  You need to use another mechanism to validate that a file is the type you are expecting, such as an image, plain text, etc.

Link to comment
Share on other sites

i have an array that checks and makes sure the file is a valid image file.

 

What do you mean?  Are you extracting the extension and just making sure it exists in Array( "gif", "jpg", "jpeg", etc. )?

 

That's exactly what I said you shouldn't be doing.

Link to comment
Share on other sites

  • 4 weeks later...
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.