Searching for all open HTML tags and closing them [PHP] -


i've got page on our church website called "the fridge" meant mimic fridge place sticky notes information on what's happening in church.

you can see here: http://www.ypc.org.au/resources/fridge

because sticky notes may various sizes , have more or less information, information on 50 characters truncated ellipses , rest of information can viewed through modal box clicking on note.

this working fine tags won't end properly. instance, if < p > tag opened , information in paragraph on 50 characters truncated before paragraph closes.

this causing invalid html , colours of notes (which being randomised through css) same colour . not huge issue nice have valid html , have colours randomised bit.

what wanting search open tag, determine open tag , once 50 characters reached, end open tags detected. know won't perfect solution if tag half opened or closed, user see that, it's easy enough add or remove few words in cirumstances.

so thinking need (but wrong; know mix of php , pseudo code):

repeat     $tag[x]     search "<" character     if found {         go next character , append $tag[x] variable until ">" character found.         $x++     } until (no more tags found)  once 50 characters reached (excluding start tag user wont see html tags),  see if tag has been closed.  if tag has not been closed {     echo "<" . $ tag . ">" end tag. } 

here simple version of how php code working fake information avoid database connections etc. (had file head section wasn't transposing onto page):

http://www.ypc.org.au/fridge.zip

if this, appreciated! it's doing head in.

you can use domdocument this:

$yourtext = "<div><span>text<em>!";  $doc = new domdocument(); $doc->loadhtml($yourtext, libxml_html_noimplied | libxml_html_nodefdtd); $yourtext = $doc->savehtml();  echo $yourtext; 

out:

<div><span>text<em>!</em></span></div> 

edit: if text truncated , happens end <p>this long text</, domdocument happily strip truncated tag out , rebuild it. raise warning did, however. suppress warning can put libxml_use_internal_errors(true); prior loadhtml().


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -