Question: I have full html code inserted into mysql database. I want to remove everything after Product Description
. How would I do it?
<p>hjfsdgfsgdfjsdgfjgdsjfgsdjgfjsdgf </p>
<p>Product Description</p>
I want to store into the database again with the html format.
Answering to the question proposed in the comments of your original question, you can do something like this:
preg_replace("/<div class=\"ui-box product-description-main\".*/sm", " ",$your_html_goes_here);
This removes everything after the div element with classes 'ui-box' and 'product-description-main'.
By the same token, answering your original question is fairly simple:
preg_replace("/(<p>Product Description<\/p>).*/sm", "$1", $your_html_goes_here);
This removes everything after the paragraph 'Product Description'. If you need more information about the regex proposed in my answer,let me know.
Do you want this?
http://php.net/manual/en/function.strip-tags.php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "
";
// Allow <p> and <a>
echo strip_tags($text, '<p><a>');
This is one way of doing it:
$lookup = "Product Description";
$fullText = "..."; //full html code goes here
$pos = strpos($fullText, $lookup);
echo substr($fullText, 0, $pos);
This will print your string contents until "Product Description" position. If you also want to get rid of possible html tags, just use strip_tags
as recommended in other answers