が、これはここではPHPの私の最初の関数であるコードヘルプを持つHTML機能させる
<html><head>
<style type="text/css">
.tright
{
float:right;
margin:5px;
}
.tleft
{
float:left;
margin:5px;
}
</style>
</head><body>
<?php
$fullstring = '[p1]{{15em}}((tleft))
\\Biography//
[[Name==My Name]]
[[Fathers Name==My Father Name]]
[[Mothers Name==My Mother Name]]
[[Date Of Birth==My Date Of Birth]]
[/p1][p1]{{15em}}((tright))
\\Biography//
[[Name==My Name]]
[[Fathers Name==My Father Name]]
[[Mothers Name==My Mother Name]]
[[Date Of Birth==My Date Of Birth]]
[/p1]';
function get_string_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
}
function Make_html($texttoprase){
//$parsed = get_string_between($texttoprase, "[p1]", "[/p1]");
$mywidth = get_string_between($texttoprase, "{{", "}}");
//replacing width variables
$texttoprase = str_replace("{{","",$texttoprase);
$texttoprase = str_replace("}}","",$texttoprase);
$texttoprase = str_replace($mywidth,"",$texttoprase);
//getiing class for table
$myclass = get_string_between($texttoprase, "((", "))");
//replacing class variables
$texttoprase = str_replace("((","",$texttoprase);
$texttoprase = str_replace("))","",$texttoprase);
$texttoprase = str_replace($myclass,"",$texttoprase);
$texttoprase = str_replace("[[","<tr><th scope=\"row\" style=\"text-align:left;\">",$texttoprase);
$texttoprase = str_replace("==","</th><td>",$texttoprase);
$texttoprase = str_replace("]]","</td></tr>",$texttoprase);
$texttoprase = str_replace("\\","<tr><td colspan=\"2\" style=\"text-align:center;\">",$texttoprase);
$texttoprase = str_replace("//","</td></tr>",$texttoprase);
return "<div class=\"" . $myclass . "\"><table style=\"width: " . $mywidth . ";\" cellspacing=\"5\"><tbody>" . $texttoprase . "</tbody></table></div>";
}
$texttofind = get_string_between($fullstring, "[p1]", "[/p1]");
$textToReplace = Make_html($texttofind) ;
$fullstring = str_replace("[p1]" . $texttofind . "[/p1]", $textToReplace ,$fullstring);
echo $fullstring;
?></body></html>
あるそれは[P1]/[P1]の最初の出現にHTMLを作るが、2番目のために任意のヘルプを作成する方法やアイディア ?
HTMLパーサを使用した方がはるかに簡単です。 –
iam PHP関数の学習 – Hafiz
あなたは最も複雑なものの1つを選択しました。 –