本文介绍了用变量爆炸字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php操纵图像的路径.路径中有一个可变的用户目录,所以我在努力编写它.

我曾经做过:

$texthtml = $content;
if (preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image) ) {
$promopic = $image['src'];
}

查找我的内容中是否有图像,并从中创建一个变量.可以,但是出于页面加载的原因,我需要更改代码以从缩略图目录加载图像.

图像src如下所示:"/uploads/userdirs/admin(variable)/image.jpg"

但是我希望它是这样:

"/uploads/userdirs/admin(variable)/mcith/mcith_image.jpg"

在映像中添加/mcith/和mcith_prefix.我正在考虑爆炸,但我不知道如何使用可变路径.任何指针都非常感谢!

解决方案

您可以执行许多不同的操作,但是我可能会使用 pathinfo()为此:

$path = pathinfo($promopic);
$thumb = $path['dirname'] . '/mcith/mcith_' . $path['basename'];

I'm trying to manipulate a path to an image using php.The path has a variable userdirectory in it, so i'm struggling with how to write this.

Ive used to do :

$texthtml = $content;
if (preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $texthtml, $image) ) {
$promopic = $image['src'];
}

to find if there is an image in my content and make a variable out of it. that works, but i need to alter my code to load image from a thumbnail directory for pageload reasons.

an image src looks like this : "/uploads/userdirs/admin(variable)/image.jpg"

But i want it to be this :

"/uploads/userdirs/admin(variable)/mcith/mcith_image.jpg"

adding a /mcith/ and a mcith_prefix to the image.I'm thinking exploding it, but i dont know how to do that with a variable path. Any pointers greatly appreciated!

解决方案

You can do this many different ways, but I would probably use pathinfo() for this:

$path = pathinfo($promopic);
$thumb = $path['dirname'] . '/mcith/mcith_' . $path['basename'];

这篇关于用变量爆炸字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 00:31