如何创建一个简单的apache重写规则来重写:
http://domain.com/vanity到http://domain.com/foo/
也可以在httpd.conf中重写规则,还是必须进入.htaccess文件?
提前致谢.
我正在研究构建一个13位数的EAN条形码扫描器,该扫描器可在移动设备上的网络上运行,并将使用设备相机拍摄条形码图像进行扫描和解码.我不是想通过原生应用程序来做这件事,因为我更愿意将这部分作为我的原生网站搜索体验.例如,移动设备上的网站访问者将被提示扫描条形码而无需打开应用程序.
此脚本在桌面https://github.com/EddieLa/JOB上运行良好,并使用Navigator.getUserMedia属性在JavaScript中完成所有这些操作,但Android中的支持才刚刚开始,并且IOS上的支持不存在http:// caniuse.com/#feat=stream
所以我想知道我是否可以改为支持移动设备,这是我想要做的事情的全部内容,而不是在浏览器中读取条形码,拍下条形码的照片,通过以下方式将其发送到服务器Ajax,让服务器解码图像并将响应发送回网页.
通过这种方法,我知道有些python脚本可以读取条形码,例如https://pypi.python.org/pypi/zbar,但是它有PHP等价吗?
你好,有一种方法用css来设置页面上第二个元素的样式,同一个类与第一个元素略有不同.
例如,我在一个topbardropdownmenu类的页面上有两个ul.我想给第二个ul一个不同的背景到第一个.有没有办法在改变html的情况下做到这一点?
如果Web服务器上文件的文件大小(例如http://www.mysite.com/myfile.js)大于0字节,是否可以继续使用javascript进行检查?如果是,则返回true或false值?
提前致谢!
我正在使用http://jquery.malsup.com/form/ ,我正在使用GET向网址发布电子邮件地址.
看起来电子邮件地址中的@正在转换为%40.
这对于捕获数据的网站来说会是一个问题吗?
我想使用GB货币格式将我的分析中的一些数字格式化为货币,但作为仪表板的格式并不需要那么精确,所以我想删除便士(小数点后的数字)并将其舍入为有帮助使用css布局,我该怎么做?向上或向下舍入到最接近的英镑就可以了.
我的代码如下:
//set locale for currency
setlocale(LC_MONETARY, 'en_GB');
$sales = '8932.83';
echo utf8_encode(money_format('%n', $sales));
Run Code Online (Sandbox Code Playgroud)
输出:£8,932.83
但是,如何在没有小数点后的任何内容的情况下将其输出为8,932英镑.
我想使用货币格式,因为有时数字是负数,在这种情况下,money_format返回的数字如 - £8,932.83,最好是£-8,932(英镑和错误方式的负数符号),这就是我使用number_format格式化时发生的事情所以:
echo '£'.number_format($sales, 0, '', ',');
Run Code Online (Sandbox Code Playgroud) 您好我需要在php中的推文中添加一个href标签,例如,如果我有这样的推文:
@username tweet body message http://t.co/sfr34s5
Run Code Online (Sandbox Code Playgroud)
我需要用php将其变成这个:
@username tweet body message <a href="http://t.co/sfr34s5">http://t.co/sfr34s5</a>
Run Code Online (Sandbox Code Playgroud)
我认为这可以使用preg_replace来完成,我有类似的东西已经在twitter @username周围包含一个链接,如下所示:
$tweet= preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $tweet);
Run Code Online (Sandbox Code Playgroud)
如何编辑此正则表达式部分,以便在出现的推文中围绕网址添加标记?
我有一个从eventbrite.com api返回的数据数组,存储在一个名为$ restrictedEvents的变量中,它看起来像下面的数据.这仅仅是为了粘贴的一个事件的代表,但它在完整数组中有大约80个这样的stdClass对象.
我想通过每个stdClass对象中的[title]键按字母顺序对此数组进行排序.我尝试过使用:
usort($restrictedEvents, "title");
Run Code Online (Sandbox Code Playgroud)
但是,这会返回以下错误:
Warning: usort() [function.usort]: Invalid comparison function in model.php on line 109
Run Code Online (Sandbox Code Playgroud)
我的猜测是它无法找到标题键,因为它处于下一级别.关于我出错的地方以及如何按标题排序的任何指示都将非常感激.非常感谢.
Array
(
[4791063199] => stdClass Object
(
[box_header_text_color] => 393837
[link_color] => EE6600
[box_background_color] => FFFFFF
[box_border_color] => D9D4D0
[timezone] => Europe/London
[organizer] => stdClass Object
(
[url] => http://www.eventbrite.com/org/2866607767
[description] =>
[long_description] =>
[id] => 2866607767
[name] => B&Q Manifestival
)
[background_color] => E3DFDC
[id] => 4791063199
[category] =>
[box_header_background_color] => F0ECE9
[capacity] => 20
[num_attendee_rows] => 0
[title] => …Run Code Online (Sandbox Code Playgroud) I have a php include which takes awhile to load because PHP has to fetch a lot of data. I don't want to slow the whole webpage loading waiting for this include so how can I load this one include with ajax? I don't want the ajax to be triggered by a button click I just want it to load up the include as the page is loading so that if you look at my example below 'Some more html …
我拼凑了下面的代码块,以帮助我通过我的Twitter帐户在我的网站上显示最新的推文.但是,它不是很正常,你可以帮我调试最后一点.我正在寻找PHP将其转换为HTML,其中链接标签包含在Twitter用户名和正在使用的链接上preg_replace.
如果你测试这个脚本,你会发现它在推文中提取标准链接的时候会出现问题,它会在过早发布关闭的<a>标签a.我确信这个修复起来相对简单,而且可能是关于转义字符或其他东西.
我的主要代码块:
<?php
/** Script to pull in the latest tweet */
$username='benpaton';
$format = 'json';
$tweet = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}"));
$latestTweet = htmlentities($tweet[0]->text, ENT_QUOTES);
$latestTweet = preg_replace('/http:\/\/([[a-z0-9_\.\-\+\&\!\#\~\,]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $latestTweet);
$latestTweet = preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $latestTweet);
echo $latestTweet;
?>
Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我的网站类中的 get_status() 方法返回 1 而不是我想要的 true 或 false。谁能告诉我为什么?我认为这可能是我班上的一个错误,我不确定这行代码是否是 get_status() 方法中的好习惯?
$httpcode = $this->get_httpcode();
当我回显 $siteUp 时,无论我将 url 设为http://www.google.com还是http://www.dsfdsfsdsdfsdfsdf.com,它始终为 1
我对面向对象的 php 还很陌生,这是我第一次自学,这是我正在构建的一个学习 oop 的例子。它旨在检查网站状态并根据 httpcode 判断它是启动还是关闭。
您对为什么这不起作用的任何提示都将大受欢迎。提前致谢!
class website {
protected $url;
function __construct($url) {
$this->url = $url;
}
public function get_url() {
return $this->url;
}
public function get_httpcode() {
//get the http status code
$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL,$this->url);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt …Run Code Online (Sandbox Code Playgroud) 我有一个包含以下列的表:
我正在尝试编写一个SQL语句,选择具有最高5星评级数的ProductId,平均评分为5,最后一次评审提交在过去三个月内.
该表看起来像这个例子:
ID ProductId rate1 rate2 rate3 rate4 rate5 aveRate lastSubDate
18 9996637 0 0 0 0 1 5 2011-08-10 12:00:34
26 9996628 1 0 0 0 0 1 2010-05-06 05:45:05
34 9996618 0 0 0 1 0 4 2011-10-09 09:00:45
36 9996614 5 0 0 0 0 1 2011-01-05 09:30:32
48 9996592 5 0 1 0 3 3 2012-11-28 19:00:06
66 9996566 0 0 0 1 …Run Code Online (Sandbox Code Playgroud) 可能重复:
提取网址的最后一部分
我有这样的网址:
http://www.domain.co.uk/product/SportingGoods/Cookware/1/B000YEU9NA/Coleman-Family-Cookset
Run Code Online (Sandbox Code Playgroud)
我想提取最后的产品名称"Coleman-Family-Cookset"
当我使用parse_url和print_r时,我最终得到以下结果:
Array (
[scheme] => http
[host] => www.domain.co.uk
[path] => /product/SportingGoods/Cookware/1/B000YEU9NA/Coleman-Family-Cookset
)
Run Code Online (Sandbox Code Playgroud)
我怎么然后修剪"Coleman-Family-Cookset"呢?
提前致谢