从变量中分离两个字符串的最佳方法 [英] Best way to separate two strings from a variable
本文介绍了从变量中分离两个字符串的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法检索了我正在寻找的数据,这些数据采用两个 url 的形式,我需要将它们提取到两个单独的变量中.我是否以最有效的方式检索数据,然后我如何拥有两个包含 url 数据的变量.
I have managed to retrieve the data I'm looking for which is in the form of two urls and I need to extract them into two separate variables. Am I retrieving the data the most efficient way and how can I then have two variables containing the url data.
$item = $this->_item;//Item ID
foreach ($item->getElements() as $elements) {
$images = $elements->get('file');
if(!empty($images)) {
$imagesnonnull = $images;
$image = JURI::base() . $imagesnonnull;
var_dump($image);
}
}
var_dump 结果如下:
The var_dump result is below:
string(33) "http://demo.com/images/image1.jpg"
string(33) "http://demo.com/images/image2.jpg"
我很乐意提供更多信息并尝试任何改进代码的建议.
I happy to provide more info and try any suggestions to improve the code.
推荐答案
您可以使用:
1- 数组
$image[] = JURI::base() . $imagesnonnull;
2- 或字符串
$image.= JURI::base() . $imagesnonnull;
这篇关于从变量中分离两个字符串的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文