PHP:获取字符串A和字符串B之间的字符串(多个字符串需要被搜索) [英] PHP: Get strings between string A and string B (multiple strings need to be searched for)

查看:479
本文介绍了PHP:获取字符串A和字符串B之间的字符串(多个字符串需要被搜索)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大的字符串,是这样的:

I have one large string which goes like this:

$string = '<span id="nothread307693965">blabla here is a lot of text blabla<span id="nothread5248574987">blabla even more text<span id="nothread9754541">';

我现在需要把所有从线程数。 ('' - >'307693965')。为此,我需要在PHP stringbetween搜索应该在一个数组返回所有的数字。

I now need to get all the numbers from the threads. ('' --> '307693965'). For this I need a stringbetween search in PHP which should return all the numbers in an array.

输出应该是:

array(3) {
  [0]=>
  int(307693965)
  [1]=>
  int(5248574987)
  [2]=>
  int(9754541)
}

这是我坚持的地方,请帮助我!

This is the place I'm stuck, please help me out!

推荐答案

您可以使用字符串函数。但对于提取的目的一个简单的正前pression还是建议最小的结构验证:

You can use string functions. But for extraction purposes a simple regular expression is advisable for minimal structure verification:

 preg_match_all('/[\s]id="nothread(\d+)"/', $html, $result);
 $numbers = $result[1];

\\ S 表示空间。和 \\ D + 匹配小数。在()括号用于捕获,因为他们是第一次,其内容将在指数显示 [1] 结果数组。

The \s means space. And the \d+ matches decimals. The ( ) braces are used for capturing, and because they are the first, their content will show up in index [1] of the result array.

这篇关于PHP:获取字符串A和字符串B之间的字符串(多个字符串需要被搜索)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆