שלום חברים,
בניתי איזשהו קוד אתמול לפני ליל הסדר (זה היה די זריז אז אולי פספסתי משהו.. בשביל זה אני מתייעץ איתכם) שהמטרה שלו זה לבדוק קוד מסויים ולחפש טאגים <intercs...></intercs> ולהחליף בהתאם.
הבעיה נובעת מכך שמשומה שאני עושה בסוף הפונקציות return $HtmlContent; הדף בטעינה שלו נתקע אבל אם אני שם במקום ה return $HtmlContent; את השורה: echo $HtmlContent; הקוד עובד.. עכשיו "למה אתה לא שם אז echo?" כי אני לא רוצה להדפיס את התוצאה אלא רק לשמור במשתנה.
אשמח לסיוע.
להלן הקוד:
PHP קוד:
<?php
function intercsTags($HtmlContent) {
$TagStart = strtolower("<intercs");
$TagEnd = strtolower("></intercs>");
while(preg_match("/<intercs (.*)><\/intercs>/i", $HtmlContent, $match)) {
$outMatch=$TagStart." ".$match[1].$TagEnd;
$Cmatch=$match[1];
$Cmatch = str_replace('"','', $Cmatch);
$Cmatch = str_replace("'","", $Cmatch);
$exp=explode(" ",$Cmatch); $expCount=count($exp);
$TagsArray=Array();
for($i=0; $i <= $expCount-1; $i++) {
$expArray = explode("=",$exp[$i]);
$TagsArray[strtolower($expArray[0])] .= strtolower($expArray[1]);
}
switch ($TagsArray['content']) {
case "articel":
$HtmlContent = str_replace($outMatch, "Articel!!!", $HtmlContent);
break;
default:
$HtmlContent = intercsUnSupported($HtmlContent, $outMatch,$TagsArray['content']);
break;
}
}
return $HtmlContent;
}
function intercsUnSupported($HtmlContent, $outMatch, $TagsArray) {
$HtmlContent = str_replace($outMatch,"<intercs ".$TagsArray."=UnSupported></intercs>" ,$HtmlContent);
return $HtmlContent;
}
$content = '';
$content = '<html>
<body>
<title>rofl</title>
welcome to my <intercs content=articel prop=5></intercs>
<br>
<intercs content=articels prop=5></intercs>
</body>
</html>';
$HtmlContent=intercsTags($content);
echo $HtmlContent;
?>