0

I have got field in database with <p>intro content</p><p>rest of content....</p>

How to remove first paragraph of content <p>intro content</p> using PHP?

Joel
  • 4,732
  • 9
  • 39
  • 54
Newbie1
  • 37
  • 1
  • 2
  • 9
  • assuming you have a string, why not just parse the string for the first instance of "" ? – Joel Dec 20 '12 at 19:21
  • 2
    Take a look at [`DOMDocument`](http://php.net/manual/en/class.domdocument.php). – Leri Dec 20 '12 at 19:23
  • Isn't there a fast a simple solution? – Newbie1 Dec 20 '12 at 19:24
  • look at Dagon's answer... or you can just query the database and then parse the result with a php function.. int index = strpos($result,""); – Joel Dec 20 '12 at 19:24
  • related: [How to parse and process HTML/XML with PHP](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-xml-with-php/3577662#3577662) – dualed Dec 20 '12 at 19:54

2 Answers2

1

assuming mysql

SELECT SUBSTRING_INDEX(content_field, '</p>', 1) as cut from TABLE

replace in db:

update [table_name] set [field_name] = replace([field_name],SUBSTRING_INDEX([field_name], '</p>', 1),'');
1

Use a DOM parser. Maybe PHPQuery. You can then select the first element from the DOM and remove it

Pseudo Code:

$dom->firstChild()->remove();
dualed
  • 10,262
  • 1
  • 26
  • 29