Jump to content

preg_replace ALL alpha numeric things and special characters before..


Gabrax

Recommended Posts

You're going to use a regular expression something preg_replace

 

<?php

$str = 'iamacr4zyfilename.jpg';

$str = preg_replace('/^.*\./', 'file1.', $str);

echo $str;

?>

 

That should change all characters before the . to 'file1'.  Don't know exactly if this is what you're looking for but you will definitely need to use some sort of regular expression to solve this problem :)

 

Link to comment
Share on other sites

u can use it like this there is one function in php

http://php.net/manual/en/function.getimagesize.php

 

which can tell you what is the type of image then u store the extension value with some string and when ever u rename the file just add the respective extension

 

just try this

<?php
$info = getimagesize("1.jpg");
foreach($info as $key => $value) {
    echo $key . ' - ' . $value . '<br />';
}
?>

Link to comment
Share on other sites

You guys are awesome! Thanks!! I have one last question

 

how do I understand those expressions within the preg_replace function?

 

this is what I am talking about : preg_replace ( '/^.*\./' )

 

where can I find more info on understanding what that expression means and how to construct my own for other instances where I want to use preg_replace?

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.