06-11-2011, 11:16
|
|
|
חבר מתאריך: 06.06.07
הודעות: 749
|
|
טוב זה מה שיצא לי
זה משהו מאוד בסיסי... אני חושב שצריך גם להסיר את כל
מה אתם אומרים
קוד PHP:
function test()
{
header('Content-Type: text/html; charset=utf-8');
$str = " נחל שניר <strong class='bla'>הוא הארוך בין שלושת יובלי נהר הירדן. חלקו של הנחל הזורם<img /> בסמוך לקיבוץ מעיין
ברוך, נמצא<br/> בתחומי שמורת</strong> טבע נחל שניר, ומציע למטי - ילים בגליל העליון מסלול מהנה במיוחד";
//$str = "Lorem Ipsum is <strong class='bla'>simply dummy<img /> text of <b>the printing</b> and typesetting
//industry. <br /> Lorem Ipsum has been</strong> the industry";
$str = trim($str);
$n = 101;
$end_char = '…';
$search = array("/\r/", "/\n/", "/\t/");
$replace = array(" ", " ", " ");
$str = preg_replace($search, $replace, $str);
$search = array(" ");
$replace = array("***");
$str = str_replace($search, $replace, $str);
$search = array("#[***]{1,}#");
$replace = array(" ");
$str = preg_replace($search, $replace, $str);
$i = 0;
$out = "";
$htmlOn = false;
$html = array();
$var = '';
$strA = preg_split('/(?<!^)(?!$)/u', $str );
foreach ($strA as $key => $value)
{
if($value === '<' && isset($strA[$key+1]) && $strA[$key+1] === '/')
{
if(!empty($html))array_pop($html);
$out .= $value;
continue;
}
elseif($value === '<')
{
$htmlOn = true;
$out .= $value;
continue;
}
if($htmlOn)
{
$out .= $value;
if($value === '>')
{
if (isset($strA[$key-1]) && $strA[$key-1] !== '/')
{
array_push($html, trim($var));
}
$htmlOn = false;
$var = '';
}
else
{
$var .= $value;
}
}
else
{
$out .= $value;
if($i == $n)
{
foreach (array_reverse($html) as $v)
{
$tag = explode(' ', $v);
$out .= '</'.$tag[0].'>';
}
break;
}
else
{
$i++;
}
}
}
var_dump(trim($out));
}
נערך לאחרונה ע"י tsachibenezra בתאריך 06-11-2011 בשעה 11:32.
|