从以下字符串Duitsland
中仅提取单词/Duitsland|/groepsreizen fietsen|Stars/1
的php函数是什么?
我尝试了所有的东西,但没有找到合适的方法。
答案 0 :(得分:0)
http://php.net/manual/de/function.str-replace.php
<w:r w:rsidRPr="00E05157">
<w:rPr>
<w:rStyle w:val="MyCharacterStyle"/>
</w:rPr>
<w:t>17-Jan-14</w:t>
</w:r>
结果:$result= str_replace("Duitsland", "", "/Duitsland|/groepsreizen fietsen|Stars/1");
答案 1 :(得分:0)
有多种方法可以完成这项工作。一种方法是使用正则表达式。在preg_match()
中使用正则表达式来查找字符串的特定单词。
$str = "/Duitsland|/groepsreizen fietsen|Stars/1";
preg_match("/[^|\/]+/", $str, $match);
echo $match[0];
您可以在demo
中对其进行测试答案 2 :(得分:0)
with strpos function find require o/p
$haystack = '/Duitsland|/groepsreizen fietsen|Stars/1';
$needle = 'Duitsland';
if (strpos($haystack,$needle) !== false) {
echo $needle;
}
答案 3 :(得分:0)
我认为这就是你要找的东西:
(此代码不需要知道之前的单词是什么,它只是在字符串中寻找第一个(尽可能长的)单词)
<?php
$str = "/Duitsland|/groepsreizen fietsen|Stars/1";
preg_match("/\w+/i", $str, $matches);
$first_word = array_shift($matches);
echo $first_word;
无论在该单词之前有多少个非字母符号,它都会起作用,即它不依赖于任何固定数量的其他字符。