简体   繁体   中英

PHP strange picture file name

I have this function in php:

foreach($rss->channel->item as $item) {
    /* Poster */
    if (!file_exists('./img/'.$item->orignaziv.' ('.$item->godina.').jpg')) {

      $remote_file = $item->plakat;
      $new_width = 117;
      $new_height = 168;
      list($width, $height) = getimagesize($remote_file);
      $image_p = imagecreatetruecolor($new_width, $new_height);
      $image = imagecreatefromjpeg($remote_file);
      imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
      header('Content-Type: image/jpeg');
      imagejpeg($image_p, './img/'.ucfirst($item->orignaziv).' ('.$item->godina.').jpg', 100);
      imagedestroy($image_p);
    }

And if poster name is for example:

Poster's Name

I get when picture is saved to my hdd this:

Poster’s Name

How to do character encoding to be displayed picture file name like in original with '?

I fixed this by converting special character ' into html entitles and then string replace with none so that is removed...i know i should use more easy and clean code like preg_replace_all to remove all non standard characters but this works...

$item->orignaziv = str_replace('’', '', mb_convert_encoding($item->orignaziv, 'HTML-ENTITIES', "UTF-8"));

This way if i put '' it gets removed all special character but if i put '\\'' it gets filename ' in name so it all works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM