我试图在第一张图片后添加块,到目前为止,我已经在第一段之后得到它了。
这是我的代码
$HPSB =' <img src="**/facebook131update1.png" border="0" alt=""/>
<p>
If you're a Facebook for iOS user and you checked the Updates tab in your App Store application recently, then you probably noticed the new Facebook version 13.1 update that was waiting there for you to install.
</p>
Facebook version 13.1 doesn't go very specific into what's new apart from "Bug Fixes," but according to Facebook's detailed ';
function callback_func($matches)
{
static $count = 0;
$ret = $matches[1];
if (++$count == 1)
$ret .= '<div style="float:left;margin:10px 10px 10px 0;">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-***";
/* iMac 336*280 */
google_ad_slot = "***";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="//pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>';
return $ret;
}
$content = preg_replace_callback('#(<p>.*?</p>)#', 'callback_func', $HPSB);
怎么能得到它,请帮助
修改
$HPSB =
<p style="text-align: center;">
<img class="size-large wp-image-566952 aligncenter" title="Here’s more evidence Apples ‘iPhone 6' event will be on Sept. 9" src="http://abcaa.com/wp-content/uploads/2014/08/btsendate.jpg" alt="Here’s more evidence Apples ‘iPhone 6' event will be on Sept. 9"/>
</a>
</p>
<p>Weve found an interesting piece of information that further backs up the recent report that Apple is planning to introduce the iPhone 6 at a special media event on Tuesday, Sept 9.</p>
<p>Apple’s Back to School promotion will also stop on that same date. </p>
<p>So it definitely makes sense that Apple doesnt want students being able to take advantage of the promotion when buying a new device.</p>
<p>With this years promotion, college students can receive a $100 Apple Store gift card with the purchase of a Mac or a $50 store gift card when they purchase an iPad or iPhone. Students can also take advantage of Apples educational pricing.</p>
<p>Along with college students, the promotion is available for parents of a student or a faculty or staff member from any grade level.</p>
<p>The next-generation handset is expected to be unveiled in both a 4.7-inch and 5.5-inch version. It should also feature a faster A8 processor, a better camera, and other improvements.</p>
<p>For other recent news, see: Read the entire Tom Hanks interview with the App Store on Twitter, all about apps.</p>
<br/>
答案 0 :(得分:1)
我不完全确定我有问题,但您可以使用以下内容获取(并传递给callback_func
p
标记内的文字
$content = preg_replace_callback("#<p>(.*?)<\/p>#is", 'callback_func', $HPSB);
---- ----- EDIT
根据我写给你的片段,你不在第一<p>
之后获取内容,但只包含其标签之间的内容。如果您想在第一<img
之后获得,则需要:
$content = preg_replace_callback("#<img.*/>(.*)#is", 'callback_func', $HPSB);
这样您就可以获得img
标记之后的所有内容。
----------编辑----------(我最后发誓)
1)包含在p
代码之间:
$content = preg_replace_callback("#<p>(.*?)<\/p>#is", 'callback_func', $HPSB);
结果($ match [1]):
If you're a Facebook for iOS user and you checked the Updates tab in your App Store application recently, then you probably noticed the new Facebook version 13.1 update that was waiting there for you to install.
' (length=222)
2) img
代码后
$content = preg_replace_callback("#<img.*/>(.*)#is", 'callback_func', $HPSB);
结果($ match [1]):
<p>
If you're a Facebook for iOS user and you checked the Updates tab in your App Store application recently, then you probably noticed the new Facebook version 13.1 update that was waiting there for you to install.
</p>
Facebook version 13.1 doesn't go very specific into what's new apart from "Bug Fixes," but according to Facebook's detailed ' (length=363)
3)现在你问第一个<img
,所以:
$content = preg_replace_callback("#(<img.*/>)#is", 'callback_func', $HPSB);
结果($ match [1]):
'<img src="**/facebook131update1.png" border="0" alt=""/>' (length=56)