這是我在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,使第二任何幫助或想法?
如果您使用了HTML解析器,您會有更容易的時間。 –
iam學習PHP函數 – Hafiz
你選擇了一個最複雜的東西,你最好學習一些更簡單的東西。 –