我试图从HTML中删除JavaScript.
我无法使用正则表达式来使用PHP; 它给了我一个空数组.为什么?
<?php
$var = '
<script type="text/javascript">
function selectCode(a)
{
var e = a.parentNode.parentNode.getElementsByTagName(PRE)[0];
if (window.getSelection)
{
var s = window.getSelection();
if (s.setBaseAndExtent)
{
s.setBaseAndExtent(e, 0, e, e.innerText.length - 1);
}
else
{
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
}
else if (document.getSelection)
{
var s = document.getSelection();
var r = document.createRange();
r.selectNodeContents(e);
s.removeAllRanges();
s.addRange(r);
}
else if (document.selection)
{
var r = document.body.createTextRange();
r.moveToElementText(e);
r.select();
}
}
</script>
';
function remove_javascript($java){
echo preg_replace('/<script\b[^>]*>(.*?)<\/script>/i', "", $java); …Run Code Online (Sandbox Code Playgroud) 我一直试图用PHP限制带宽.我无法通过PHP限制下载速率.
你能帮忙吗?
function total_filesize($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLINFO_SPEED_DOWNLOAD,12); //ITS NOT WORKING!
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) ".
"Gecko/20071127 Firefox/2.0.0.11");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, true);
$chStore = curl_exec($ch);
$chError = curl_error($ch);
$chInfo = curl_getinfo($ch);
curl_close($ch);
return $size = $chInfo['download_content_length'];
}
function __define_url($url) {
$basename = basename($url);
Define('filename',$basename);
$define_file_size = total_filesize($url);
Define('filesizes',$define_file_size);
}
function _download_file($url_file) {
__define_url($url_file);
// $range = "50000-60000";
$filesize = filesizes;
$file …Run Code Online (Sandbox Code Playgroud)