Work encountered a lot of small checkpoints, after searching for information can be solved, now unified collation and collection, convenient in the future encountered similar problems can be quickly solved. Continuously updated…

PHP converts the image URL into a binary file stream and passes it back to the front end

Application scenario: can hide the real path of the picture, hide the project file structure

Implementation method:

$image_info = getimagesize($img_url); echo 'data:' . $image_info['mime'] . '; base64,' . chunk_split(base64_encode(file_get_contents($img_url)));Copy the code

Replaces the image URL in the string

Application scenario: Replace the image URL of a string with multiple characters

Implementation method:

$address = www.baidu.com'; $goods_info = preg_replace('/((http|https):\/\/)+(\w+\.) +(\w+)[\w\/\.\-]/', "$1".$address."{$supplier}/", $goods_info);Copy the code