Премини към съдържанието
cyriliano

Според вас защо това не работи на php5

Препоръчан отговор


Този скрипт работи без проблем на php4 ама на 5 не ще?

<?

class o_Template

{

var $p_strOutputContents = "";

var $p_arrSections = array();

var $p_arrPaired = array();

function m_LoadFile($strFile, $strTagName = "")

{ $objFile = fopen($strFile, "r");

$strContents = fread($objFile, filesize($strFile));

fclose($objFile);

if (empty($strTagName))

{ $this->p_strOutputContents = $strContents;

}

else

{ $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strContents, $this->p_strOutputContents);

};

}

function m_AssignContent($strTagName, $strReplace, $strContent="")

{

if (empty($strContent))

{ $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strReplace, $this->p_strOutputContents);

}

else

{ return str_replace("{{" . $strTagName . "}}", $strReplace, $strContent);

};

}

function m_DefineSection($strSectionName)

{ $longSectionStart = strpos($this->p_strOutputContents, "{{section $strSectionName }}");

$longSectionEnd = strpos($this->p_strOutputContents, "{{/section $strSectionName }}");

if (($longSectionEnd > 0))

{ $longSectionLength = $longSectionEnd - $longSectionStart + strlen("{{/section $strSectionName }}");

$strSection = substr($this->p_strOutputContents, $longSectionStart, $longSectionLength);

$this->p_arrSections[$strSectionName] = trim($strSection);

return $this->p_arrSections[$strSectionName];

};

}

function m_AssignSection($strSectionName, $strReplace, $strContent="")

{ $strSection = trim($this->p_arrSections[$strSectionName]);

if (empty($strContent))

{

if (!empty($strSection))

{ $this->p_strOutputContents = str_replace(trim($strSection), $strReplace . "\r\n" . $strSection, $this->p_strOutputContents);

};

}

else

{

if (!empty($strSection))

{ return str_replace($strSection, $strReplace . "\r\n" . $strSection, $strContent);

};

};

}

function m_DefinePair($strPairName, $boolUseBoth=false)

{ $longFirstStart = strpos($this->p_strOutputContents, "{{paired $strPairName }}");

$longFirstEnd = strpos($this->p_strOutputContents, "{{/paired $strPairName }}");

$longSecondStart = strpos($this->p_strOutputContents, "{{unpaired $strPairName }}");

$longSecondEnd = strpos($this->p_strOutputContents, "{{/unpaired $strPairName }}");

if (($longFirstEnd > 0))

{ $longFirstLength = $longFirstEnd - $longFirstStart + strlen("{{/paired $strPairName }}");

$longSecondLength = $longSecondEnd - $longSecondStart + strlen("{{/unpaired $strPairName }}");

$strFirstPairContents = substr($this->p_strOutputContents, $longFirstStart, $longFirstLength);

$strSecondPairContents = substr($this->p_strOutputContents, $longSecondStart, $longSecondLength);

$this->p_arrPaired[$strPairName][0] = trim($strFirstPairContents);

if ($boolUseBoth)

{ $this->p_arrPaired[$strPairName][1] = trim($strSecondPairContents);

}

return $this->p_arrPaired[$strPairName][0];

};

}

function m_AssignPair($strPairName, $strFirstReplace, $strSecondReplace="")

{ $strFirstPair = $this->p_arrPaired[$strPairName][0];

if (!empty($strFirstPair))

{ $this->p_strOutputContents = str_replace($strFirstPair, $strFirstReplace . "\r\n" . $strFirstPair, $this->p_strOutputContents);

if (!empty($strSecondReplace))

{ $strSecondPair = $this->p_arrPaired[$strPairName][1];

$this->p_strOutputContents = str_replace($strSecondPair, $strSecondReplace . "\r\n" . $strSecondPair, $this->p_strOutputContents);

};

};

}

function m_AddElements($strPageTitle)

{ $this->m_LoadFile("templates/navigation.tpl","NAVIGATION");

$this->m_LoadFile("templates/footer.tpl","FOOTER");

$this->m_AssignContent("TITLE","DWF - " . $strPageTitle);

}

function m_PrepTemplate($boolDeleteSection = true)

{

if ($boolDeleteSection)

{ $arrSections = $this->p_arrSections;

while (list($strSectionName, $strSectionContent) = each($arrSections))

{ $this->p_strOutputContents = str_replace(trim($strSectionContent), "", $this->p_strOutputContents);

$this->p_strOutputContents = str_replace("{{section " . $strSectionName . " }}", "", $this->p_strOutputContents);

$this->p_strOutputContents = str_replace("{{/section " . $strSectionName . " }}", "", $this->p_strOutputContents);

};

$arrPair = $this->p_arrPaired;

while (list($strPairName) = each($arrPair))

{

while (list($intArrayVal, $strPairContent) = each($arrPair["$strPairName"]))

{ $this->p_strOutputContents = str_replace(trim($strPairContent), "", $this->p_strOutputContents);

};

$this->p_strOutputContents = str_replace("{{paired " . $strPairName . " }}", "", $this->p_strOutputContents);

$this->p_strOutputContents = str_replace("{{/paired " . $strPairName . " }}", "", $this->p_strOutputContents);

$this->p_strOutputContents = str_replace("{{unpaired " . $strPairName . " }}", "", $this->p_strOutputContents);

$this->p_strOutputContents = str_replace("{{/unpaired " . $strPairName . " }}", "", $this->p_strOutputContents);

};

};

return $this->p_strOutputContents;

}

function m_Output()

{ echo $this->p_strOutputContents;

}

}

$objTemplate = new o_Template;

$objTemplate->m_LoadFile("templates/template.tpl");

$objTemplate->m_AddElements("Tester Page");

$objTemplate->m_AssignContent("BODY_TEXT","This is the body text");

$strImageSection = $objTemplate->m_DefineSection("Image");

$strImageInfo = $objTemplate->m_AssignContent("IMAGE","images/log.gif",$strImageSection);

$strImageInfo = $objTemplate->m_AssignContent("IMAGE_NAME","Our corporate logo",$strImageInfo);

$objTemplate->m_AssignSection("Image", $strImageInfo);

$objTemplate->m_AssignSection("Image", $strImageInfo);

$strGroupSection = $objTemplate->m_DefineSection("Group");

$strItemSection = $objTemplate->m_DefineSection("Item");

$strGroup = $objTemplate->m_AssignContent("GROUP_NAME", "First Group", $strGroupSection);

$strItem = $objTemplate->m_AssignContent("ITEM_NAME", "First Item, ", $strItemSection);

$strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strItemSection);

$strItem = $objTemplate->m_AssignContent("ITEM_NAME", "Second Item", $strItemText);

$strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strGroup);

$objTemplate->m_AssignSection("Group", $strItemText);

$strGroup = $objTemplate->m_AssignContent("GROUP_NAME", "Second Group", $strGroupSection);

$strItem = $objTemplate->m_AssignContent("ITEM_NAME", "First Item, ", $strItemSection);

$strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strItemSection);

$strItem = $objTemplate->m_AssignContent("ITEM_NAME", "Second Item", $strItemText);

$strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strGroup);

$objTemplate->m_AssignSection("Group", $strItemText);

$strLinkPair = $objTemplate->m_DefinePair("Link", true);

$strLink = $objTemplate->m_AssignContent("LINK","click.html", $strLinkPair);

$strLinkRight = $objTemplate->m_AssignContent("CAPTION","The link caption", $objTemplate->p_arrPaired["Link"][1]);

$objTemplate->m_AssignPair("Link", $strLink, $strLinkRight);

$objTemplate->m_PrepTemplate();

$objTemplate->m_Output();

?>

Ползвам wamp server s php 5.2.3

Сподели този отговор


Линк към този отговор
Сподели в други сайтове

Някаква грешка не извежда ли ?

Дай я ако има ! Няма сега да дебъгваме на монитора.

Сподели този отговор


Линк към този отговор
Сподели в други сайтове

Niama greshki http://svilengrad.biz/kiro/test.php ei twa e rezultata pri php 4 a pri 5 eto towa e izhoda w explorera

p_strOutputContents = $strContents; } else { $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strContents, $this->p_strOutputContents); }; } function m_AssignContent($strTagName, $strReplace, $strContent="") { if (empty($strContent)) { $this->p_strOutputContents = str_replace("{{" . $strTagName . "}}", $strReplace, $this->p_strOutputContents); } else { return str_replace("{{" . $strTagName . "}}", $strReplace, $strContent); }; } function m_DefineSection($strSectionName) { $longSectionStart = strpos($this->p_strOutputContents, "{{section $strSectionName }}"); $longSectionEnd = strpos($this->p_strOutputContents, "{{/section $strSectionName }}"); if (($longSectionEnd > 0)) { $longSectionLength = $longSectionEnd - $longSectionStart + strlen("{{/section $strSectionName }}"); $strSection = substr($this->p_strOutputContents, $longSectionStart, $longSectionLength); $this->p_arrSections[$strSectionName] = trim($strSection); return $this->p_arrSections[$strSectionName]; }; } function m_AssignSection($strSectionName, $strReplace, $strContent=") { $strSection = trim($this->p_arrSections[$strSectionName]); if (empty($strContent)) { if (!empty($strSection)) { $this->p_strOutputContents = str_replace(trim($strSection), $strReplace . "\r\n" . $strSection, $this->p_strOutputContents); }; } else { if (!empty($strSection)) { return str_replace($strSection, $strReplace . "\r\n" . $strSection, $strContent); }; }; } function m_DefinePair($strPairName, $boolUseBoth=false) { $longFirstStart = strpos($this->p_strOutputContents, "{{paired $strPairName }}"); $longFirstEnd = strpos($this->p_strOutputContents, "{{/paired $strPairName }}"); $longSecondStart = strpos($this->p_strOutputContents, "{{unpaired $strPairName }}"); $longSecondEnd = strpos($this->p_strOutputContents, "{{/unpaired $strPairName }}"); if (($longFirstEnd > 0)) { $longFirstLength = $longFirstEnd - $longFirstStart + strlen("{{/paired $strPairName }}"); $longSecondLength = $longSecondEnd - $longSecondStart + strlen("{{/unpaired $strPairName }}"); $strFirstPairContents = substr($this->p_strOutputContents, $longFirstStart, $longFirstLength); $strSecondPairContents = substr($this->p_strOutputContents, $longSecondStart, $longSecondLength); $this->p_arrPaired[$strPairName][0] = trim($strFirstPairContents); if ($boolUseBoth) { $this->p_arrPaired[$strPairName][1] = trim($strSecondPairContents); } return $this->p_arrPaired[$strPairName][0]; }; } function m_AssignPair($strPairName, $strFirstReplace, $strSecondReplace="") { $strFirstPair = $this->p_arrPaired[$strPairName][0]; if (!empty($strFirstPair)) { $this->p_strOutputContents = str_replace($strFirstPair, $strFirstReplace . "\r\n" . $strFirstPair, $this->p_strOutputContents); if (!empty($strSecondReplace)) { $strSecondPair = $this->p_arrPaired[$strPairName][1]; $this->p_strOutputContents = str_replace($strSecondPair, $strSecondReplace . "\r\n" . $strSecondPair, $this->p_strOutputContents); }; }; } function m_AddElements($strPageTitle) { $this->m_LoadFile("templates/navigation.tpl","NAVIGATION"); $this->m_LoadFile("templates/footer.tpl","FOOTER"); $this->m_AssignContent("TITLE","DWF - " . $strPageTitle); } function m_PrepTemplate($boolDeleteSection = true) { if ($boolDeleteSection) { $arrSections = $this->p_arrSections; while (list($strSectionName, $strSectionContent) = each($arrSections)) { $this->p_strOutputContents = str_replace(trim($strSectionContent), "", $this->p_strOutputContents); $this->p_strOutputContents = str_replace("{{section " . $strSectionName . " }}", "", $this->p_strOutputContents); $this->p_strOutputContents = str_replace("{{/section " . $strSectionName . " }}", "", $this->p_strOutputContents); }; $arrPair = $this->p_arrPaired; while (list($strPairName) = each($arrPair)) { while (list($intArrayVal, $strPairContent) = each($arrPair["$strPairName])) { $this->p_strOutputContents = str_replace(trim($strPairContent), "", $this->p_strOutputContents); }; $this->p_strOutputContents = str_replace("{{paired " . $strPairName . " }}", "", $this->p_strOutputContents); $this->p_strOutputContents = str_replace("{{/paired " . $strPairName . " }}", "", $this->p_strOutputContents); $this->p_strOutputContents = str_replace("{{unpaired " . $strPairName . " }}", "", $this->p_strOutputContents); $this->p_strOutputContents = str_replace("{{/unpaired " . $strPairName . " }}", "", $this->p_strOutputContents); }; }; return $this->p_strOutputContents; } function m_Output() { echo $this->p_strOutputContents; } } $objTemplate = new o_Template; $objTemplate->m_LoadFile("templates/template.tpl"); $objTemplate->m_AddElements("Tester Page"); $objTemplate->m_AssignContent("BODY_TEXT","This is the body text"); $strImageSection = $objTemplate->m_DefineSection("Image"); $strImageInfo = $objTemplate->m_AssignContent("IMAGE","images/log.gif",$strImageSection); $strImageInfo = $objTemplate->m_AssignContent("IMAGE_NAME","Our corporate logo",$strImageInfo); $objTemplate->m_AssignSection("Image", $strImageInfo); $objTemplate->m_AssignSection("Image", $strImageInfo); $strGroupSection = $objTemplate->m_DefineSection("Group"); $strItemSection = $objTemplate->m_DefineSection("Item"); $strGroup = $objTemplate->m_AssignContent("GROUP_NAME", "First Group", $strGroupSection); $strItem = $objTemplate->m_AssignContent("ITEM_NAME", "First Item, ", $strItemSection); $strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strItemSection); $strItem = $objTemplate->m_AssignContent("ITEM_NAME", "Second Item", $strItemText); $strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strGroup); $objTemplate->m_AssignSection("Group", $strItemText); $strGroup = $objTemplate->m_AssignContent("GROUP_NAME", "Second Group", $strGroupSection); $strItem = $objTemplate->m_AssignContent("ITEM_NAME", "First Item, ", $strItemSection); $strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strItemSection); $strItem = $objTemplate->m_AssignContent("ITEM_NAME", "Second Item", $strItemText); $strItemText = $objTemplate->m_AssignSection("Item", $strItem, $strGroup); $objTemplate->m_AssignSection("Group", $strItemText); $strLinkPair = $objTemplate->m_DefinePair("Link", true); $strLink = $objTemplate->m_AssignContent("LINK","click.html", $strLinkPair); $strLinkRight = $objTemplate->m_AssignContent("CAPTION","The link caption", $objTemplate->p_arrPaired["Link"][1]); $objTemplate->m_AssignPair("Link", $strLink, $strLinkRight); $objTemplate->m_PrepTemplate(); $objTemplate->m_Output(); ?>

Сподели този отговор


Линк към този отговор
Сподели в други сайтове

Това не е от версията, а настройка на сървъра:

short_open_tag boolean

Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).

Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.

Сподели този отговор


Линк към този отговор
Сподели в други сайтове

Регистрирайте се или влезете в профила си за да коментирате

Трябва да имате регистрация за да може да коментирате това

Регистрирайте се

Създайте нова регистрация в нашия форум. Лесно е!

Нова регистрация

Вход

Имате регистрация? Влезте от тук.

Вход


×

Информация

Този сайт използва бисквитки (cookies), за най-доброто потребителско изживяване. С използването му, вие приемате нашите Условия за ползване.