Hey guys i have the following code and i need to be able to look through a section of html and pick out all the elements that have the classname cmsedit. The code below does that however if the element has new lines or tabs in it ect the the preg_match_all doesnt work

Help ?

function FindEdits($text, $regex"){ $EditArray = array(); preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $EditArray[] = array($type,$result[0][$i]); } return $EditArray; } 

FindEdits($HtmlContent,"|<h1(.*?)class=\"(.*?)cmsedit(.*?)\"(.*?)>(.*?)</h1>|");

Try this.

FindEdits($HtmlContent,"@<h1(.*)?class=\"(.*)?cmsedit(.*)?\"(.*)?>(.*)?</h1>@ius");

Also could you post the data your trying to match.

Ok so lets say the html content is

<div class="cmsedit">
<div>come content</div>
</div>

The following code will pick the wrong end tag.

function FindEdits($text, $regex"){ $EditArray = array(); preg_match_all($regex, $text, $result, PREG_PATTERN_ORDER); for ($i = 0; $i < count($result[0]); $i++) { $EditArray[] = array($type,$result[0][$i]); } return $EditArray; } 

FindEdits($HtmlContent,"|<div(.*?)class=\"(.*?)cmsedit(.*?)\"(.*?)>(.*?)</div>|");

The idea of it. is to look through a html document and pick out all the elements that have a class of cmsedit.

Then display the contents of those elements in input fields so a client can edit them. If the element is a <h1> tag then it will display a input field which works fine. but if its got html contents in it then i want to display a textarea which will later become a wysiwyg editor.

Then once they have been edited find the original element & its contents and replace them with the one the client edited.

So its basically a very simple CMS.


Any help would be greatly appreciated.

Try this.

FindEdits($HtmlContent,"@<div(.*?)class=\"(.*?)cmsedit(.*?)\"(.*?)>(.*?)</div>@Us");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.