Your coding intent is to use <hr id="system-readmore" />
as your "string delimiter". For this type of task there are several functions that can lead you to the desired output. The most direct attack will be to call a function which will split your string in half then you can simply reference the two pieces.
Here is a demonstration of two splitting functions (take note of what happens with the possible leading/trailing whitespace characters):
Code: (Demo)
// this is your $this->row->product_description value for demonstration purposes:
$html = <<<HTML
Some text yatta yatta
<hr id="system-readmore" />
Some more text blah blah
HTML;
list($introtext, $description) = explode('<hr id="system-readmore" />', $html, 2);
var_dump($introtext);
var_dump($description);
echo "\n---\n";
var_dump(trim($introtext)); // this is tidier, with leading/trailing whitespace characters removed
var_dump(trim($description)); // this is tidier, with leading/trailing whitespace characters removed
echo "\n---\n";
list($introtext, $description) = preg_split('~\s*<hr id="system-readmore" />\s*~', $html, 2);
var_dump($introtext); // no trim() call, no leading/trailing whitespace characters displayed
var_dump($description); // no trim() call, no leading/trailing whitespace characters displayed
Output:
string(22) "Some text yatta yatta
"
string(25) "
Some more text blah blah"
---
string(21) "Some text yatta yatta"
string(24) "Some more text blah blah"
---
string(21) "Some text yatta yatta"
string(24) "Some more text blah blah"
Best coding practices, with a particular stress on efficiency/micro-optimization, states that you should only use regex if there is a particular advantage in doing so. If your delimiting string NEVER has whitespaces on either side, then you can use explode()
without any trim()
calls. If your delimiting string MAY have spaces, tabs, or newlines then I will recommend preg_split()
because you receive 2 clean strings without any mopping up.
For your project, you would just use echo
on the resulting variables. I used var_dump()
to expose the whitespaces.
If you don't want to use list()
. You can store the result of explode()
as $halves
and write echo $halves[0];
for the introtext and echo $halves[1];
for the description.
p.s. As I said, there are a few functions that will get your there. You could use preg_match()
with ~^(.*?)\s*<hr id="system-readmore" />\s*(.*?)$~s
(Demo) but this provides the unwanted fullstring match in its output. For future development with regex pattern, I highly endorse regex101.com because it not only highlights your matches in real time, it also gives an itemized breakdown of how your pattern is interpreted by the regex engine and offers the "step count" as a loose measure of pattern efficiency.