Cakephp Classroom image

Anil  Bist / Professional / Web Technology

 
To post your Question Join Classroom
 
Question No  (2 of 18)
First 1 I 2 I 3 I 4 I 5 I 6 I 7 I 8 I 9 Last
 
Question:-

Get the first 200 characters of a string without breaking HTML tags at the end

 
Answer:-

<?php

function closetags($html) {

preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);

$openedtags = $result[1];

preg_match_all('#</([a-z]+)>#iU', $html, $result);

$closedtags = $result[1];

$len_opened = count($openedtags);

if (count($closedtags) == $len_opened) {

return $html;

}

$openedtags = array_reverse($openedtags);

for ($i=0; $i < $len_opened; $i++) {

if (!in_array($openedtags[$i], $closedtags))

{

$html .= '</'.$openedtags[$i].'>';

} else {

unset($closedtags[array_search($openedtags[$i], $closedtags)]);

}

}

return $html;

} ?>

  
 
 
 
image
Anil  Bist

Skills    Cakephp

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (5)

Ask 
image
Rohin
Ask 
Sanjay
Ask 
Riya
Ask 
image
deepu
Ask 
image
divya
 
 

Recommended Classes

image shweta Pandey
Passionate about LIFE and Learning. Lets explore together better version of "self", &qu...
Professional
image shweta Pandey
Passionate about LIFE and Learning. Lets explore together better version of "self", &qu...
Professional
image shweta Pandey
Passionate about LIFE and Learning. Lets explore together better version of "self", &qu...
Professional