infernothebest
Gebruiker
- Lid geworden
- 25 feb 2008
- Berichten
- 76
kan iemand deze code korter/efficiënter maken?
PHP:
$stripedhtml = strip_tags($content, '<img>');
$doc=new DOMDocument();
$doc->loadHTML($stripedhtml);
$xml=simplexml_import_dom($doc); // just to make xpath more simple
$images=$xml->xpath('//img');
$plaatje = $images[0]['src'] ;
$stripedhtml1 = strip_tags($content, ' ');
$text1 = $stripedhtml1;
$uitkomst = preg_replace('/(\(\.\.\.\).+|\[\.\.\.\].+)/','',$text1);
$overgeblevenwoorden =implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$uitkomst), 0, 53));
$result= rtrim($overgeblevenwoorden, ', ');
$result2= rtrim($result, ',');
$result3= rtrim($result2, '. ');
$result4= rtrim($result3, '.');
$result5= rtrim($result4, '(...)');
$result6= rtrim($result5, '(...) ');
$result7= rtrim($result6, '[...]');
$result8= rtrim($result7, '[...] ');
$result9= rtrim($result8, '? ');
$result10= rtrim($result9, '?');
$result11= rtrim($result10, '! ');
$result12= rtrim($result11, '!');
$string = $result12;
$arr=array();
preg_match_all('/\b([0-9A-Za-z]{3,})\b/', $string, $arr);
$keywords = array_slice(array_unique($arr[0]),-4,4);
$overgeblevenwoorden =implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), -4, 4));
$testt = join(' ', $keywords );
if (trim($testt) == $overgeblevenwoorden) {
echo $string;
}else{
preg_match_all('/\b([0-9A-Za-z]{3,})\b/', $string, $arr);
$keywords = array_slice(array_unique($arr[0]),-2,2);
$overgeblevenwoorden =implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), -2, 2));
$testt = join(' ', $keywords );
if (trim($testt) == $overgeblevenwoorden) {
preg_match_all('/\b([0-9A-Za-z]{3,})\b/', $string, $arr);
$keywords = array_slice(array_unique($arr[0]),-3,3);
$overgeblevenwoorden =implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), -3, 3));
$testt = join(' ', $keywords );
if (trim($testt) == $overgeblevenwoorden) {
preg_match_all('/\b([0-9A-Za-z]{3,})\b/', $string, $arr);
$keywords = array_slice(array_unique($arr[0]),-4,4);
$overgeblevenwoorden =implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), -4, 4));
$testt = join(' ', $keywords );
if (trim($testt) == $overgeblevenwoorden) {
}else{
$bladieblahuitkomst = implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), 0, str_word_count($string) - 4));
}
}else{
$bladieblahuitkomst = implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), 0, str_word_count($string) - 3));
}
}else{
$bladieblahuitkomst = implode(" ", array_slice(preg_split("/[:\|\\\\\/\s]/",$string), 0, str_word_count($string) - 2));
}
}
$eindresultaat= $bladieblahuitkomst."...";
if (empty($plaatje)) {
$echteind = $eindresultaat;
}else{
$echteind = '<img class="alignleft" src='.$plaatje.' />'.$eindresultaat;
}