[英]PHP Compatibility Check Inside HTML
Is there anyway I can use this code inside a html file? 无论如何,我可以在html文件中使用此代码吗?
I have tried everything possible and can't seem to get it to work... 我已经尝试了所有可能的方法,但似乎无法使其正常工作...
Any help would be greatly appreciated.. Thanks! 任何帮助将不胜感激..谢谢!
$isUDIDProtected=TRUE;
$compatibleVersions=array("8.1.1","8.1","8.0");
I was the top code for each php file 我是每个php文件的最高代码
if ($isUDIDProtected)
{
echo "<p style=\"color: red;\">This package is UDID protected! You must have your device registered to download this package</p>";
}
if ($compatibleVersions)
{
$uaString = $_SERVER["HTTP_USER_AGENT"];
if (preg_match("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/", $uaString)) {
$version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/","$2.$3.$4", $uaString);
} else if (preg_match("/(.*) OS ([0-9]*)_([0-9]*) (.*)/", $uaString)) {
$version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*) (.*)/","$2.$3", $uaString);
}
if ($version) {
if (in_array($version, $compatibleVersions)) {
echo "<p style=\"color: green;\">This package is compatible with your iOS version :)</p>";
} else {
echo "<p style=\"color: #FFCC00\">This package is not comfirmed to work on your iOS version</p>";
}
}
}
The html file is below html文件在下面
<ul data-role="listview" data-inset="true">
<li data-role="list-divider"><center>Compatibility</center></li>
<li><center>(show yes or no)</center></li>
</ul>
您需要根据是否构造情况,在html代码中的php打开和关闭标签下添加php代码。
Your code is PHP code. 您的代码是PHP代码。 It won't work inside an "html" file.
它无法在“ html”文件中运行。 You need to place it inside a PHP file (with corresponding php tags) and run it through the server.
您需要将其放在一个PHP文件(带有相应的php标记)中,并通过服务器运行它。 Being said this, you could have a "compat.php" file with the code:
话虽如此,您可能会有一个带有代码的“ compat.php”文件:
$compatibleVersions=array("8.1.1","8.1","8.0");
if ($compatibleVersions)
{
$uaString = $_SERVER["HTTP_USER_AGENT"];
if (preg_match("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/", $uaString)) {
$version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*)_([0-9]*) (.*)/","$2.$3.$4", $uaString);
} else if (preg_match("/(.*) OS ([0-9]*)_([0-9]*) (.*)/", $uaString)) {
$version = preg_replace("/(.*) OS ([0-9]*)_([0-9]*) (.*)/","$2.$3", $uaString);
}
if (isset($version) && in_array($version, $compatibleVersions)) {
echo "<p style=\"color: green;\">This package is compatible with your iOS version :)</p>";
} else {
echo "<p style=\"color: #FFCC00\">This package is not comfirmed to work on your iOS version</p>";
}
}
Then, inside another file "htmlPage.php", something like: 然后,在另一个文件“ htmlPage.php”中,类似:
<?php
$isUDIDProtected=TRUE;
if ($isUDIDProtected)
{
echo "<p style=\"color: red;\">This package is UDID protected! You must have your device registered to download this package</p>";
die();
}
?>
<ul data-role="listview" data-inset="true">
<li data-role="list-divider"><center>Compatibility</center></li>
<li><center><?php include "compat.php" ?></center></li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.