0

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>|");
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by cwarn23
0

Try this.

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

Also could you post the data your trying to match.

0

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.

Edited by semanticart: n/a

0

Try this.

FindEdits($HtmlContent,"@<div(.*?)class=\"(.*?)cmsedit(.*?)\"(.*?)>(.*?)</div>@Us");
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.