我有这样的东西:
"YAKUGAKU ZASSHI-日本药学会杂志YAKUGAKU ZASSHI"
并想从中删除第二个"YAKUGAKU ZASSHI"(粗体)。我该怎么做?
我有一个列表,在每一行中,在第一行和最后都重复一些内容,我想删除在最后重复的内容。我该怎么做?
更新:
我找到了解决方案,所以我只想更新我的问题,以防有人遇到同样的问题。
因此,实际上我正试图从以下网站获取期刊列表及其缩写:http://images.webofknowledge.com/WOK46/help/WOS/Y_abrvjt.html
然后将其显示为期刊名称:缩写
但我从网站上得到的是错误的,因为定义列表DT和DD标签没有关闭。
所以实际上我有两个字符串,$dd和$dt$dd在$dt.所以这就是我删除重复项所做的:
$length=strlen($dd); // get length of the dd
$ddN=explode(' ', $dd); // split the dd and put in new variable called $ddN
$extra=$ddN[0]; // get the first word of dd
$pos=strripos($dt,$extra); // find the position of the last occurrence of $extra in $dt, which is first word of $dd
$result=substr($dt,$pos,-$length); //removing the duplicate from end of the dd
echo '"' . $result . '"' . ' : ' . '"' . $dd . '"' . '<br>';
如果您能够使用正则表达式,这里有一个小的解决方案。
$textWithoutLastWord = preg_replace('/'W'w+'s*('W*)$/', '$1', $words);
或使用功能:
$lastSpacePosition = strrpos($text, ' ');
$textWithoutLastWord = substr($text, 0, $lastSpacePosition);
据我所知,您希望避免标题(句子)中出现重复单词。这可以通过以下方式实现:
<?php
//Our input string - can be from database, or whatever, trimmed from ending/trailing spaces
$string = trim("YAKUGAKU ZASSHI-JOURNAL OF THE PHARMACEUTICAL SOCIETY OF JAPAN YAKUGAKU ZASSHI");
//Convert title to array of words
$array = explode (" ", $string);
//How many elements we have in array
$count = count($array);
//Remove the last 2
unset($array[$count-1]);
unset($array[$count-2]);
print_r ($array);
?>
检查一下这把小提琴。
我找到了解决方案,所以我只想更新我的问题,以防有人遇到同样的问题。
因此,实际上我正试图从以下网站获取期刊列表及其缩写:http://images.webofknowledge.com/WOK46/help/WOS/Y_abrvjt.html
然后将其显示为期刊名称:缩写
但我从网站上得到的是错误的,因为定义列表DT和DD标签没有关闭。
所以实际上我有两个字符串,$dd和$dt$dd在$dt.所以这就是我删除重复项所做的:
$length=strlen($dd); // get length of the dd
$ddN=explode(' ', $dd); // split the dd and put in new variable called $ddN
$extra=$ddN[0]; // get the first word of dd
$pos=strripos($dt,$extra); // find the position of the last occurrence of $extra in $dt, which is first word of $dd
$result=substr($dt,$pos,-$length); //removing the duplicate from end of the dd
echo '"' . $result . '"' . ' : ' . '"' . $dd . '"' . '<br>';