如何使用PHP更改此内部图像链接参数?

时间:2015-09-04 作者:Kamarul Anuar

如何调整此字符串的大小/更改链接参数。

原始文件=mydomain。com/wp-content/uploads/2015/01/name文件。jpg公司

现在返回$字符串=mydomain。com/wp-content/uploads/2015/01/name-file-300x215。jpg公司

但是,我希望这个大小返回到(-90x90)=mydomain。com/wp-content/uploads/2015/01/name-file-90x90。jpg公司

<?php

    //sometime string return this value
    $string = \'mydomain.com/wp-content/uploads/2015/01/name-file-300x215.jpg\';

    //and sometime string return like this (original size)
    // $string = \'mydomain.com/wp-content/uploads/2015/01/name-file.jpg\';

    //or sometime string return like this (external image link)
    // $string = \'otherdomain.com/wp-content/uploads/2015/01/name-file.jpg\';

    //the point now, i want this newstring return like this
    // $string = \'mydomain.com/wp-content/uploads/2015/01/name-file-90x90.jpg\';

    if(strpos($tring, \'mydomain.com/wp-content/uploads\') !== false ){ //check if this string is internal image link

    // SO WHAT TO DO BELOW? 
    $newstring = \'\'; // i want this $newstring return this value -> mydomain.com/wp-content/uploads/2015/01/name-file-90x90.jpg

    //so i can return this $newstring (new image size 90x90) if string is internal image link
    $return $newstring; 
    } else {
//external image, no need change link parameter
    return $string;
    }
    ?>

1 个回复
SO网友:user2960701

如果您正在使用wordpress,本指南可能会帮助您-https://developer.wordpress.org/reference/functions/add_image_size/