Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php在div之前和comman之后获取字符串的一部分_Php_String - Fatal编程技术网

php在div之前和comman之后获取字符串的一部分

php在div之前和comman之后获取字符串的一部分,php,string,Php,String,谁能帮帮我吗?我只需要使用PHP获取字符串中的单词部分。在以下示例中,我需要从以下字符串中获取单词Kimberley: 13 Angel Street, El Toro Park, Kimberley <div Id='rentals' Class='rentals'>Agencies</div> <div Id='rentalsix' Class='rentals'>5</div> 13金伯利市埃尔托罗公园天使街5号 我尝试了以下方法: $s

谁能帮帮我吗?我只需要使用PHP获取字符串中的单词部分。在以下示例中,我需要从以下字符串中获取单词Kimberley:

13 Angel Street, El Toro Park, Kimberley <div Id='rentals' Class='rentals'>Agencies</div> <div Id='rentalsix' Class='rentals'>5</div>
13金伯利市埃尔托罗公园天使街5号
我尝试了以下方法:

$searchaddress = 13 Angel Street, El Toro Park, Kimberley <div Id='rentals' 
Class='rentals'>Agencies</div> <div Id='rentalsix' Class='rentals'>5</div>;

preg_match('|<[^>]*rentals[^>]*>(.*?)<|', $searchaddress, $m);
$newvalue = $m[1];
echo htmlspecialchars($newvalue));
$searchaddress=13天使街,埃尔托罗公园,金伯利5号;

preg_match('|]*rentals[^>]*>(.*)
$exp=explode('
$exp=explode('要忽略HTML标记,请使用
strip_标记
PHP函数。 有关详细信息,请参阅此链接

如果要在第一个div之前使用第一个字符串,请使用
explode
函数

$searchaddress = 13 Angel Street, El Toro Park, Kimberley <div Id='rentals' 
Class='rentals'>Agencies</div> <div Id='rentalsix' Class='rentals'>5</div>;

strip_tags($searchaddress);
$searchaddress=13天使街,埃尔托罗公园,金伯利5号;
带标签($searchaddress);
仅获取字符串的第一部分

$str   =   explode("<div",$searchaddress);
echo $str[0];

$str=explode(“要忽略HTML标记,请使用
strip\u标记
PHP函数。 有关详细信息,请参阅此链接

如果要在第一个div之前使用第一个字符串,请使用
explode
函数

$searchaddress = 13 Angel Street, El Toro Park, Kimberley <div Id='rentals' 
Class='rentals'>Agencies</div> <div Id='rentalsix' Class='rentals'>5</div>;

strip_tags($searchaddress);
$searchaddress=13天使街,埃尔托罗公园,金伯利5号;
带标签($searchaddress);
仅获取字符串的第一部分

$str   =   explode("<div",$searchaddress);
echo $str[0];

$str=explode(我希望这会有所帮助

  //this is your string.
    $text = '13 Angel Street, El Toro Park, Kimberley <div Id=\'rentals\' Class=\'rentals\'>Agencies</div> <div Id=\'rentalsix\' Class=\'rentals\'>5</div>';
    //find position of ',' from where you want to explode using strrpos
        $pos=strrpos($text,',',2);
    // explode string from given postion.
        $text=substr($text,$pos);
    //find the text that exist between ',' and  starting bracket of div '<'
        preg_match('#,(.*?)<#', $text, $match);
    // output
        var_dump( $match[1]);
//这是您的字符串。
$text='13天使街,埃尔托罗公园,金伯利5';
//使用strrpos从要爆炸的位置查找“,”的位置
$pos=strrpos($text,’,2);
//从给定位置分解字符串。
$text=substr($text,$pos);

//查找“,”和div的起始括号之间的文本我希望这会有所帮助

  //this is your string.
    $text = '13 Angel Street, El Toro Park, Kimberley <div Id=\'rentals\' Class=\'rentals\'>Agencies</div> <div Id=\'rentalsix\' Class=\'rentals\'>5</div>';
    //find position of ',' from where you want to explode using strrpos
        $pos=strrpos($text,',',2);
    // explode string from given postion.
        $text=substr($text,$pos);
    //find the text that exist between ',' and  starting bracket of div '<'
        preg_match('#,(.*?)<#', $text, $match);
    // output
        var_dump( $match[1]);
//这是您的字符串。
$text='13天使街,埃尔托罗公园,金伯利5';
//使用strrpos从要爆炸的位置查找“,”的位置
$pos=strrpos($text,’,2);
//从给定位置分解字符串。
$text=substr($text,$pos);

//查找存在于“,”和div的起始括号之间的文本是否需要这两个词?Kimbherley和Agencies?并且是否区分大小写。是否尝试使用
explode(“嗨,谢谢你的回复。不,我只需要金伯利的作品。请你也可以试试这个简单的正则表达式,在
之前找到单词。你需要这两个单词吗?Kimbherley和Agencies?这个例子具体吗?你试过
explode吗?”(“嗨,谢谢你的回复。不,我只需要金伯利的作品。请你也可以试试这个简单的正则表达式,在
之前得到这个单词。这非常好用。谢谢。即使它包含两个或两个以上的单词,它也会得到城市名称。这非常好用。谢谢你。即使它包含两个或两个以上的单词,它也会得到城市名称。