Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the difficulty is that the random text can also contain commas.</p> <p>If the keywords are all on one line and it is the last line of the text as a whole, trim the whole text removing new line characters from the end. Then take the text from the last new line character to the end. This should be your string containing the keywords. Once you have this part singled out, you can explode the string on comma and count the parts.</p> <pre><code>&lt;?php $string = " some gibberish, some more gibberish, and random text keyword1, keyword2, keyword3 "; $lastEOL = strrpos(trim($string), PHP_EOL); $keywordLine = substr($string, $lastEOL); $keywords = explode(',', $keywordLine); echo "Number of keywords: " . count($keywords); </code></pre> <p>I know it is not a regex, but I hope it helps nevertheless.</p> <p>The only way to find a solution, is to find something that separates the random text and the keywords that is not present in the keywords. If a new line is present in the keywords, you can not use it. But are 2 consecutive new lines? Or any other characters.</p> <pre><code>$string = " some gibberish, some more gibberish, and random text keyword1, keyword2, keyword3, keyword4, keyword5, keyword6, keyword7, keyword8, keyword9 "; $lastEOL = strrpos(trim($string), PHP_EOL . PHP_EOL); // 2 end of lines after random text $keywordLine = substr($string, $lastEOL); $keywords = explode(',', $keywordLine); echo "Number of keywords: " . count($keywords); </code></pre> <p>(edit: added example for more new lines - long shot)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload