dongzhi9032 2016-11-09 18:50
浏览 7

计算两个标签之间的单词作为foreach

A post have some quotes. When a quote have more then X words, I have to display a error message. To count a string between two words I use this function / code:

function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}

$fullstring = '<div class="quotecontent">This is the message with a lot of text</div>';

$parsed = get_string_between($fullstring, 'content">', '</div>');

$parsed_clean = strip_tags($parsed);

echo str_word_count($parsed_clean);

Now I have the amount of words inside of the quote.

Problem:

When the message have more then 1 quote, the function count only the words from the first quote and not from the others. How is it possible to count the text from every quote and display a error message with the text:

"Please check your quotes. Minimum 1 Quote is longer then X Words".

This shows the code in action.

http://ideone.com/PQAYUm

This shows the problem.

http://ideone.com/8bpnsq

Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 三种调度算法报错 有实例
    • ¥15 关于#python#的问题,请各位专家解答!
    • ¥200 询问:python实现大地主题正反算的程序设计,有偿
    • ¥15 smptlib使用465端口发送邮件失败
    • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
    • ¥15 对于squad数据集的基于bert模型的微调
    • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
    • ¥20 steam下载游戏占用内存
    • ¥15 CST保存项目时失败
    • ¥20 java在应用程序里获取不到扬声器设备