使用 PHP 切片图像 src 字符串
Slice image src string with PHP
我正在尝试使用 PHP 从基于 XML 的 Atom Feed 中提取图像 src。我想通过对提要中的字符串进行切片来做到这一点,以便只抓取 URL。
到目前为止,我已经能够使用 substr()
命令来分割特定的字符串长度。问题是图像的长度 URLs 在 Feed 中经常会有所不同,因此我需要根据特定字符进行切片。
我尝试使用 explode 指定要切片的字符:
foreach ($array['entry'] as $post) {
if ($current > $max) break;
$posts[] = [
'post_img' => explode("\"", $post['content'], 2),
...但这没有用。这是我试图从中提取的 XML 代码:
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
这里是完整的方法。 url
、post_content
和 post_title
字段都正确分配:
$feed = getRssFile();
if ($feed == false) return;
$xml = simplexml_load_file($feed);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
$posts = [];
if (count($array['entry'])) {
$max = 3;
$current = 1;
foreach ($array['entry'] as $post) {
if ($current > $max) break;
$posts[] = [
'post_img' => explode("src=", $post['content'], //isn't working
'post_title' => $post['title'],
'post_content' => substr(sanitizeContent($post['content']), 0, 200),
'url' => $post['link']['@attributes']['href']
];
$current++;
}
}
return $posts;
}
当我检查元素检查器时,explode() 没有为图像的 src 字段分配任何内容。它只是说 img src(unknown)
除了获得我需要的结果还有其他选择吗?
编辑:这是return编辑的内容
$exp = explode("src=", $thing);
var_dump($exp[1]);
var_dump($exp);
结果:
string(226) ""http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" /><iframe style="border: none" " array(3) { [0]=> string(43) " string(226) ""http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" /><iframe style="border: none" " [2]=> string(3454) ""//html5-player.libsyn.com/embed/episode/id/9576506/height/90/theme/custom/thumbnail/yes/direction/forward/render-playlist/no/custom-color/000000/" height="90" width="50%" scrolling="no" allowfullscreen="" webkitallowfullscreen="" mozallowfullscreen="" oallowfullscreen="" msallowfullscreen=""><span id="selection-marker-1" class="redactor-selection-marker"></span></iframe> <p><em><br></em></p> <p><em>If you’re interested in more conversations like this on The New CCO, subscribe on <span class="redactor-unlink"></span><span class="redactor-unlink"></span><a href="https://podcasts.apple.com/us/podcast/upskilling-a-workforce-reggie-walker-pwc/id1212422149?i=1000436862014" target="_blank">iTunes</a>, <span class="redactor-unlink"></span><a href="https://play.google.com/music/m/Dd6jidfd7eq4pzgwx7p3w6gigxm?t=Upskilling_a_Workforce_-_Reggie_Walker_PwC-The_New_CCO" target="_blank">Google Play</a>, or <span class="redactor-unlink"></span><span class="redactor-unlink"></span><a href="https://open.spotify.com/show/5oLW0nzEPyNo7mfcSFfIcu?si=gDn3b288RoiG8k9Xz9xH6g" target="_blank">Spotify</a>.</em></p> <p class="text-center">* * *</p> <p>Enterprises face severe disruption, whether via technology, business model, new competition, etc. In order to keep up, organizations must answer fundamental questions about the nature of their business, starting with their people. “What kind of culture do we need to compete in our industry? What does it look like, feel like, sound like? What are the base skills our people possess? Where do they come from?” </p> <p>These are some of the questions Reggie Walker, Chief Commercial Officer at PwC, has wrestled with while leading the enterprise's communications function over the past three years. He’s led a critical organization-wide effort around digital upskilling to better align PwC’s people with its business strategy. He’s also unified the Communications, Sales and Marketing functions, streamlining an operation that was once disparate entities. </p> <p>On this episode of The New CCO, we’ll learn more about each of these initiatives from Reggie and how they ladder up to a new kind of CCO role that’s swiftly changing in order to adapt to new disruptive factors. </p> <p>Here’s Reggie’s take on where he sees the future of work going over the next five years:</p> <p>“The opportunities are almost endless. We have to be responsible. And by that I mean there’s a lot of things we can do with technology. We have to make sure we’re not overextending the reach of certain technologies and cannibalizing jobs and opportunities. But, man, where will it not take us? That’s the fun part.”</p> <p><em>Do you have a story to tell? Share it with us. Please reach out to Justin Pallenik at <a href="mailto:jpallenik@page.org" target="_blank">jpallenik@page.org</a> with your CCO story.</em></p>" } string(3252) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg" /><p>
而且我只想 return 每个图像源分别,例如
"http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg", "http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
基本上想删除所有其他内容,例如样式标签和其他格式之间的文本。
编辑 2 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:page.org,2005:/blog</id>
<link rel="alternate" type="text/html" href="https://page.org"/>
<link rel="self" type="application/atom+xml" href="https://page.org/blog.atom"/>
<title>Blog | Arthur W. Page Society</title>
<updated>2019-04-29T16:00:00Z</updated>
<entry>
<id>tag:page.org,2005:BlogPost/29039</id>
<published>2019-04-29T16:00:00Z</published>
<updated>2019-04-30T15:52:28Z</updated>
<link rel="alternate" type="text/html" href="https://page.org/blog/the-new-cco-podcast-upskilling-a-workforce-reggie-walker-pwc"/>
<title>The New CCO Podcast: Upskilling a Workforce - Reggie Walker, PwC</title>
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" />&lt;iframe style=&quot;border: none&quot; src=&quot;//html5-player.libsyn.com/embed/episode/id/9576506/height/90/theme/custom/thumbnail/yes/direction/forward/render-playlist/no/custom-color/000000/&quot; height=&quot;90&quot; width=&quot;50%&quot; scrolling=&quot;no&quot; allowfullscreen=&quot;&quot; webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; oallowfullscreen=&quot;&quot; msallowfullscreen=&quot;&quot;&gt;&lt;span id=&quot;selection-marker-1&quot; class=&quot;redactor-selection-marker&quot;&gt;&lt;/span&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;em&gt;&lt;br&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you’re interested in more conversations like this on The New CCO, subscribe on&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://podcasts.apple.com/us/podcast/upskilling-a-workforce-reggie-walker-pwc/id1212422149?i=1000436862014&quot; target=&quot;_blank&quot;&gt;iTunes&lt;/a&gt;,&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://play.google.com/music/m/Dd6jidfd7eq4pzgwx7p3w6gigxm?t=Upskilling_a_Workforce_-_Reggie_Walker_PwC-The_New_CCO&quot; target=&quot;_blank&quot;&gt;Google Play&lt;/a&gt;, or&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://open.spotify.com/show/5oLW0nzEPyNo7mfcSFfIcu?si=gDn3b288RoiG8k9Xz9xH6g&quot; target=&quot;_blank&quot;&gt;Spotify&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p class=&quot;text-center&quot;&gt;* * *&lt;/p&gt;
&lt;p&gt;Enterprises face severe disruption, whether via technology, business model, new competition, etc. In order to keep up, organizations must answer fundamental questions about the nature of their business, starting with their people. “What kind of culture do we need to compete in our industry? What does it look like, feel like, sound like? What are the base skills our people possess? Where do they come from?”&amp;nbsp;&lt;/p&gt;
&lt;p&gt;These are some of the questions Reggie Walker, Chief Commercial Officer at PwC, has wrestled with while leading the enterprise&#39;s communications function over the past three years. He’s led a critical organization-wide effort around digital upskilling to better align PwC’s people with its business strategy. He’s also unified the Communications, Sales and Marketing functions, streamlining an operation that was once disparate entities.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On this episode of The New CCO, we’ll learn more about each of these initiatives from Reggie and how they ladder up to a new kind of CCO role that’s swiftly changing in order to adapt to new disruptive factors.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here’s Reggie’s take on where he sees the future of work going over the next five years:&lt;/p&gt;
&lt;p&gt;“The opportunities are almost endless. We have to be responsible. And by that I mean there’s a lot of things we can do with technology. We have to make sure we’re not overextending the reach of certain technologies and cannibalizing jobs and opportunities. But, man, where will it not take us? That’s the fun part.”&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Do you have a story to tell? Share it with us. Please reach out to Justin Pallenik at &lt;a href=&quot;mailto:jpallenik@page.org&quot; target=&quot;_blank&quot;&gt;jpallenik@page.org&lt;/a&gt; with your CCO story.&lt;/em&gt;&lt;/p&gt;</content>
<author>
您没有正确使用 explode 来完成您想要做的事情。 Explode
<?php
$thing = "<content type=\"html\"><img alt=\"\" class=\"attachment image image\" src=\"http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg\"";
var_dump($thing);
$exp = explode("src=", $thing);
var_dump($exp);
?>
[root@test ~]# ./test.php
string(246) "<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
array(2) {
[0]=>
string(67) "<content type="html"><img alt="" class="attachment image image" "
[1]=>
string(175) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
}
额外的引号是出于示例目的将其推入字符串的副产品,但如果它始终是字符串的最后一个元素,这将为您提供 URL 。如果不是,您可以使用 $exp[1]
并使用 space (" ") 作为针头并使用 $exp[1
] 作为大海捞针再次爆炸它。生成的数组将 URL 作为其第一个元素。
OP 更新 Comment/Code:
请阅读 explode 的文档。
$thing is assigned to a specific string
Explode 仅适用于字符串。如果我对您的解释正确,那么我放入示例字符串中的 xml 值...
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
是$post['content']
的值。如果是这样,那么这就是您要分解的字符串。您缺少的部分:
分解return一个数组
要获取单个分解字符串,您需要引用结果数组的正确索引。再次查看我的初始示例,以确切了解爆炸的内容 returns:
array(2) {
[0]=>
string(67) "<content type="html"><img alt="" class="attachment image image" "
[1]=>
string(175) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
}
这是一个用字符串填充的数组。通过将 explode 的 return 分配给该键 'post_img'
,您使该值成为整个数组,而不是单个字符串。在 $posts 中创建一个多维数组,然后尝试像引用单个元素一样引用值,这是行不通的。
如果这仍然不能说明问题,请提供 XML 被 simplexml_load_file()
编辑的完整示例。
我正在尝试使用 PHP 从基于 XML 的 Atom Feed 中提取图像 src。我想通过对提要中的字符串进行切片来做到这一点,以便只抓取 URL。
到目前为止,我已经能够使用 substr()
命令来分割特定的字符串长度。问题是图像的长度 URLs 在 Feed 中经常会有所不同,因此我需要根据特定字符进行切片。
我尝试使用 explode 指定要切片的字符:
foreach ($array['entry'] as $post) {
if ($current > $max) break;
$posts[] = [
'post_img' => explode("\"", $post['content'], 2),
...但这没有用。这是我试图从中提取的 XML 代码:
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
这里是完整的方法。 url
、post_content
和 post_title
字段都正确分配:
$feed = getRssFile();
if ($feed == false) return;
$xml = simplexml_load_file($feed);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
$posts = [];
if (count($array['entry'])) {
$max = 3;
$current = 1;
foreach ($array['entry'] as $post) {
if ($current > $max) break;
$posts[] = [
'post_img' => explode("src=", $post['content'], //isn't working
'post_title' => $post['title'],
'post_content' => substr(sanitizeContent($post['content']), 0, 200),
'url' => $post['link']['@attributes']['href']
];
$current++;
}
}
return $posts;
}
当我检查元素检查器时,explode() 没有为图像的 src 字段分配任何内容。它只是说 img src(unknown)
除了获得我需要的结果还有其他选择吗?
编辑:这是return编辑的内容
$exp = explode("src=", $thing);
var_dump($exp[1]);
var_dump($exp);
结果:
string(226) ""http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" /><iframe style="border: none" " array(3) { [0]=> string(43) " string(226) ""http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" /><iframe style="border: none" " [2]=> string(3454) ""//html5-player.libsyn.com/embed/episode/id/9576506/height/90/theme/custom/thumbnail/yes/direction/forward/render-playlist/no/custom-color/000000/" height="90" width="50%" scrolling="no" allowfullscreen="" webkitallowfullscreen="" mozallowfullscreen="" oallowfullscreen="" msallowfullscreen=""><span id="selection-marker-1" class="redactor-selection-marker"></span></iframe> <p><em><br></em></p> <p><em>If you’re interested in more conversations like this on The New CCO, subscribe on <span class="redactor-unlink"></span><span class="redactor-unlink"></span><a href="https://podcasts.apple.com/us/podcast/upskilling-a-workforce-reggie-walker-pwc/id1212422149?i=1000436862014" target="_blank">iTunes</a>, <span class="redactor-unlink"></span><a href="https://play.google.com/music/m/Dd6jidfd7eq4pzgwx7p3w6gigxm?t=Upskilling_a_Workforce_-_Reggie_Walker_PwC-The_New_CCO" target="_blank">Google Play</a>, or <span class="redactor-unlink"></span><span class="redactor-unlink"></span><a href="https://open.spotify.com/show/5oLW0nzEPyNo7mfcSFfIcu?si=gDn3b288RoiG8k9Xz9xH6g" target="_blank">Spotify</a>.</em></p> <p class="text-center">* * *</p> <p>Enterprises face severe disruption, whether via technology, business model, new competition, etc. In order to keep up, organizations must answer fundamental questions about the nature of their business, starting with their people. “What kind of culture do we need to compete in our industry? What does it look like, feel like, sound like? What are the base skills our people possess? Where do they come from?” </p> <p>These are some of the questions Reggie Walker, Chief Commercial Officer at PwC, has wrestled with while leading the enterprise's communications function over the past three years. He’s led a critical organization-wide effort around digital upskilling to better align PwC’s people with its business strategy. He’s also unified the Communications, Sales and Marketing functions, streamlining an operation that was once disparate entities. </p> <p>On this episode of The New CCO, we’ll learn more about each of these initiatives from Reggie and how they ladder up to a new kind of CCO role that’s swiftly changing in order to adapt to new disruptive factors. </p> <p>Here’s Reggie’s take on where he sees the future of work going over the next five years:</p> <p>“The opportunities are almost endless. We have to be responsible. And by that I mean there’s a lot of things we can do with technology. We have to make sure we’re not overextending the reach of certain technologies and cannibalizing jobs and opportunities. But, man, where will it not take us? That’s the fun part.”</p> <p><em>Do you have a story to tell? Share it with us. Please reach out to Justin Pallenik at <a href="mailto:jpallenik@page.org" target="_blank">jpallenik@page.org</a> with your CCO story.</em></p>" } string(3252) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg" /><p>
而且我只想 return 每个图像源分别,例如
"http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg", "http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
基本上想删除所有其他内容,例如样式标签和其他格式之间的文本。
编辑 2 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:page.org,2005:/blog</id>
<link rel="alternate" type="text/html" href="https://page.org"/>
<link rel="self" type="application/atom+xml" href="https://page.org/blog.atom"/>
<title>Blog | Arthur W. Page Society</title>
<updated>2019-04-29T16:00:00Z</updated>
<entry>
<id>tag:page.org,2005:BlogPost/29039</id>
<published>2019-04-29T16:00:00Z</published>
<updated>2019-04-30T15:52:28Z</updated>
<link rel="alternate" type="text/html" href="https://page.org/blog/the-new-cco-podcast-upskilling-a-workforce-reggie-walker-pwc"/>
<title>The New CCO Podcast: Upskilling a Workforce - Reggie Walker, PwC</title>
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/c881c9ec924cfd1ee7f0650f2b6de9b36d4e31a9/store/limit/452/300/25f7a5696d2bd1d5e4d1137924ff04e3e2c8333fa8c71e005462a4e710d9/Walker_Recording.jpg" />&lt;iframe style=&quot;border: none&quot; src=&quot;//html5-player.libsyn.com/embed/episode/id/9576506/height/90/theme/custom/thumbnail/yes/direction/forward/render-playlist/no/custom-color/000000/&quot; height=&quot;90&quot; width=&quot;50%&quot; scrolling=&quot;no&quot; allowfullscreen=&quot;&quot; webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; oallowfullscreen=&quot;&quot; msallowfullscreen=&quot;&quot;&gt;&lt;span id=&quot;selection-marker-1&quot; class=&quot;redactor-selection-marker&quot;&gt;&lt;/span&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;em&gt;&lt;br&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you’re interested in more conversations like this on The New CCO, subscribe on&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://podcasts.apple.com/us/podcast/upskilling-a-workforce-reggie-walker-pwc/id1212422149?i=1000436862014&quot; target=&quot;_blank&quot;&gt;iTunes&lt;/a&gt;,&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://play.google.com/music/m/Dd6jidfd7eq4pzgwx7p3w6gigxm?t=Upskilling_a_Workforce_-_Reggie_Walker_PwC-The_New_CCO&quot; target=&quot;_blank&quot;&gt;Google Play&lt;/a&gt;, or&amp;nbsp;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;span class=&quot;redactor-unlink&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://open.spotify.com/show/5oLW0nzEPyNo7mfcSFfIcu?si=gDn3b288RoiG8k9Xz9xH6g&quot; target=&quot;_blank&quot;&gt;Spotify&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p class=&quot;text-center&quot;&gt;* * *&lt;/p&gt;
&lt;p&gt;Enterprises face severe disruption, whether via technology, business model, new competition, etc. In order to keep up, organizations must answer fundamental questions about the nature of their business, starting with their people. “What kind of culture do we need to compete in our industry? What does it look like, feel like, sound like? What are the base skills our people possess? Where do they come from?”&amp;nbsp;&lt;/p&gt;
&lt;p&gt;These are some of the questions Reggie Walker, Chief Commercial Officer at PwC, has wrestled with while leading the enterprise&#39;s communications function over the past three years. He’s led a critical organization-wide effort around digital upskilling to better align PwC’s people with its business strategy. He’s also unified the Communications, Sales and Marketing functions, streamlining an operation that was once disparate entities.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On this episode of The New CCO, we’ll learn more about each of these initiatives from Reggie and how they ladder up to a new kind of CCO role that’s swiftly changing in order to adapt to new disruptive factors.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here’s Reggie’s take on where he sees the future of work going over the next five years:&lt;/p&gt;
&lt;p&gt;“The opportunities are almost endless. We have to be responsible. And by that I mean there’s a lot of things we can do with technology. We have to make sure we’re not overextending the reach of certain technologies and cannibalizing jobs and opportunities. But, man, where will it not take us? That’s the fun part.”&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Do you have a story to tell? Share it with us. Please reach out to Justin Pallenik at &lt;a href=&quot;mailto:jpallenik@page.org&quot; target=&quot;_blank&quot;&gt;jpallenik@page.org&lt;/a&gt; with your CCO story.&lt;/em&gt;&lt;/p&gt;</content>
<author>
您没有正确使用 explode 来完成您想要做的事情。 Explode
<?php
$thing = "<content type=\"html\"><img alt=\"\" class=\"attachment image image\" src=\"http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg\"";
var_dump($thing);
$exp = explode("src=", $thing);
var_dump($exp);
?>
[root@test ~]# ./test.php
string(246) "<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
array(2) {
[0]=>
string(67) "<content type="html"><img alt="" class="attachment image image" "
[1]=>
string(175) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
}
额外的引号是出于示例目的将其推入字符串的副产品,但如果它始终是字符串的最后一个元素,这将为您提供 URL 。如果不是,您可以使用 $exp[1]
并使用 space (" ") 作为针头并使用 $exp[1
] 作为大海捞针再次爆炸它。生成的数组将 URL 作为其第一个元素。
OP 更新 Comment/Code:
请阅读 explode 的文档。
$thing is assigned to a specific string
Explode 仅适用于字符串。如果我对您的解释正确,那么我放入示例字符串中的 xml 值...
<content type="html"><img alt="" class="attachment image image" src="http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg"
是$post['content']
的值。如果是这样,那么这就是您要分解的字符串。您缺少的部分:
分解return一个数组
要获取单个分解字符串,您需要引用结果数组的正确索引。再次查看我的初始示例,以确切了解爆炸的内容 returns:
array(2) {
[0]=>
string(67) "<content type="html"><img alt="" class="attachment image image" "
[1]=>
string(175) ""http://awpagesociety.com/attachments/20aa91b841d6a49dd945a97af37509add2680573/store/limit/452/300/e6941ac426f6cbca5774cad6f2e8b6447c96d92d32957be6709dac201de7/Brady-Bush.jpg""
}
这是一个用字符串填充的数组。通过将 explode 的 return 分配给该键 'post_img'
,您使该值成为整个数组,而不是单个字符串。在 $posts 中创建一个多维数组,然后尝试像引用单个元素一样引用值,这是行不通的。
如果这仍然不能说明问题,请提供 XML 被 simplexml_load_file()
编辑的完整示例。