我想调用require_once("test.php")但不显示结果并将其保存到变量中,如下所示:
$test = require_once('test.php');
//some operations like $test = preg_replace(…);
echo $test;
Run Code Online (Sandbox Code Playgroud)
解:
test.php的
<?php
$var = '/img/hello.jpg';
$res = <<<test
<style type="text/css">
body{background:url($var)#fff !important;}
</style>
test;
return $res;
?>
Run Code Online (Sandbox Code Playgroud)
main.php
<?php
$test = require_once('test.php');
echo $test;
?>
Run Code Online (Sandbox Code Playgroud) 我在nginx或Apache中重写了这个地址:
http://domain.com/hello
Run Code Online (Sandbox Code Playgroud)
像一个脚本
http://domain.com/test.php&ref=hell
Run Code Online (Sandbox Code Playgroud)
如何在PHP中访问此重写的URL?因为,如果我$_SERVER['REQUEST_URI']当然使用我得到:
/test.php&ref=hell
Run Code Online (Sandbox Code Playgroud)
但我只想要:
/hello
Run Code Online (Sandbox Code Playgroud)
这可能吗?Thanx寻求帮助.
Upd nginx cnf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
server
{
listen 80;
server_name domain.test;
location /
{
rewrite ^/(main|best|air)$ /core/feeds.php?act=$1 last;
proxy_pass http://127.0.0.1:8080;
}
}
Run Code Online (Sandbox Code Playgroud) 如何使用HTMLPurifier过滤xss,还允许使用iframe Vimeo和Youtube视频?
require_once 'htmlpurifier/library/HTMLPurifier.auto.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('HTML.Trusted', true);
$config->set('Filter.YouTube', true);
$config->set('HTML.DefinitionID', '1');
$config->set('HTML.SafeObject', 'true');
$config->set('Output.FlashCompat', 'true');
$config->set('HTML.FlashAllowFullScreen', 'true');
$purifier = new HTMLPurifier($config);
$temp = $purifier->purify($temp);
Run Code Online (Sandbox Code Playgroud) 我有这个例子:
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Google Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Run Code Online (Sandbox Code Playgroud)
当用户选择选项(使用鼠标或键盘)时,我需要捕获一个事件.
我试着做onchange ="MySuperFunction();" 但这仅适用于选择项目然后列表未聚焦的情况.
我有一个主要的领域:main.com,子:test1.main.com,test2.main.com和其他领域one.com,two.com.
现在它像这样完成:
ini_set("session.cookie_domain", ".main.com");
$domain = 'main.com';
Run Code Online (Sandbox Code Playgroud)
的login.php
$user = $db->query("SELECT id, login FROM users WHERE email=? AND password=?",
array($email, $password), "rowassoc");
if($user)
{
$_SESSION['user_id'] = $user['id'];
$_SESSION['user_name'] = $user['login'];
$time = 100000;
setcookie('email', $email, time() + $time, "/", "." . $domain);
setcookie('password', $password, time() + $time, "/", "." . $domain);
header('Location: http://' . $user['login'] . "." . $domain);
exit;
}
Run Code Online (Sandbox Code Playgroud)
在每页上添加:
if(!isset($_SESSION['user_id']))
{
if(isset($_COOKIE['email']) && isset($_COOKIE['password']))
{
$email = …Run Code Online (Sandbox Code Playgroud) 我有MySQL MyISAM表:
表朋友(id,friend_id):
1,5
5,1
2,6
6,2
3,7
如何删除反向记录?如果记录值"1,5"存在值为"5,1"的记录,则需要删除"5,1".
Thanx寻求帮助!
我该如何简化这段代码?
#user_panel .subscribe,
#user_panel .faves,
#user_panel .tags,
#user_panel .title,
#user_panel .calendar a,
#user_panel .item .content
{
color:#fc0;
}
Run Code Online (Sandbox Code Playgroud)
我不想一直写#user_panel.无论如何?
我想找到文本中的所有链接,如下所示:
Test text http://hello.world Test text
http://google.com/file.jpg Test text https://hell.o.wor.ld/test?qwe=qwe Test text
test text http://test.test/test
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用preg_match_all,但只有头脑中的想法:从http | https | ftp开始搜索并在文本的空格或末尾出现的结束搜索,这就是我真正需要的所有内容,因此所有链接都可以正确找到.
任何人都可以帮助我使用php regexp模式?
我想我需要在模式结束时使用断言,但现在无法理解它们的正确用法.
有任何想法吗?感谢名单!
这里的代码(在php 5.3.5和5.2.13中执行):
$res = array(1, 2, 3);
unset($res[0]);
for($i = 0; $i < sizeof($res); $i++)
{
echo $res[$i] . '<br />';
}
Run Code Online (Sandbox Code Playgroud)
结果我看到了
<br />2<br />
Run Code Online (Sandbox Code Playgroud)
为什么只有一个元素,并且首先是空的?不明白.做的时候:
print_r($res);
Run Code Online (Sandbox Code Playgroud)
看到:
Array ( [1] => 2 [2] => 3 )
Run Code Online (Sandbox Code Playgroud)
Thanx寻求帮助!