小编Ton*_*bet的帖子

使用谷歌翻译API翻译PHP $字符串

google'ing一段时间用PHP翻译谷歌翻译的最佳方式是什么,发现转换URLs或使用Js的方式非常不同但我想只用php(或者用一个非常简单的解决方案JS/JQUery)来做

例:

//hopefully with $from_lan and $to_lan being like 'en','de', .. or similar
function translate($from_lan, $to_lan, $text){

// do

return $translated_text;

}
Run Code Online (Sandbox Code Playgroud)

你能告诉我一个线索吗?或者你已经有了这个功能..

我的意图是它只用于我尚未定义的语言(或我没有定义的键),这就是为什么我想它如此简单,只会暂时...

编辑

感谢您的回复,我们正在尝试这个问题:

function auto_translate($from_lan, $to_lan, $text){
// do


$json = json_decode(file_get_contents('https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($text) . '&langpair=' . $from_lan . '|' . $to_lan));
$translated_text = $json->responseData->translatedText;


return $translated_text;
Run Code Online (Sandbox Code Playgroud)

}

(对于lang的变量有一个额外的'g'...无论如何)

它返回:现在工作:)

我真的不太了解这个功能,所以任何想法为什么都没有点击这个对象?(现在我这样做)

要么:

    function auto_translate($from_lan, $to_lan, $text){
    // do

//    $json = json_decode(file_get_contents('https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($text) . '&langpair=' . $from_lan . '|' . $to_lan));
//    $translated_text = $json['responseData']['translatedText'];
    error_reporting(1); …
Run Code Online (Sandbox Code Playgroud)

php google-translate

12
推荐指数
2
解决办法
4万
查看次数

如何检查是否已存在与元素关联的单击/事件

让我说我有

function trigger(){

    $('a.pep').each(function(){
            $('a.pep').click(function(){
            console.log($(this).val());
        });
    });
}
function push(){
    $('body').append('<a class="pep">hey mate i have no trigger yet</a>');
    trigger();  //now i do but the others have duplicated trigger
}
$(document).ready(function(){
     $('a.push').click(function(){
        push();
     });
});
Run Code Online (Sandbox Code Playgroud)

所以似乎click事件被应用了两次/ +因为console.log通过点击多次激活

我该如何防止这种情况?

javascript jquery events

12
推荐指数
2
解决办法
1465
查看次数

将缓存控制设置为外部资源?

@ tools.pingdom.com由于这些资源,我在杠杆缓存控制中收到警告:

http://code.jquery.com/jquery-1.6.2.min.js
http://www.google-analytics.com/ga.js
http://edge.sharethis.com/images/spinner.gif
http://w.sharethis.com/button/buttons.js
Run Code Online (Sandbox Code Playgroud)

哪些不在我的主人.

我该怎么办?

这是我的htaccess的开始:

# 480 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>

# 1 weeks
<FilesMatch "\.(js)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

javascript jquery cache-control

12
推荐指数
1
解决办法
2万
查看次数

如何从mysql查询中只获取一行

我总是这样做

$q = "select whatIwant FROM table where id = 'myId'";
$r = mysql_query($q);
while($i = mysql_fetch_array($r){
   /* iterate just one withem */
   $j = $i['whatIwant'];
}
echo $j;
Run Code Online (Sandbox Code Playgroud)

这通常是怎么做的?(我只是想避免不必要的循环)

php mysql

12
推荐指数
2
解决办法
5万
查看次数

无法连接到memcache

我正在尝试连接到memcache,因为他们建议:

$memcache = new Memcache();
$memcache->pconnect('localhost',11211);
Run Code Online (Sandbox Code Playgroud)

但我得到:

Notice: Memcache::pconnect() [memcache.pconnect]: Server localhost (tcp 11211) failed with: Connection refused (111) in /home/user/public_html/website.com/includes/basedatos.php on line 26
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

php apache memcached caching

12
推荐指数
3
解决办法
3万
查看次数

Varnish似乎正在工作,但max-age = 0

isvarnishworking.com让我知道

Varnish似乎在该URL响应,但Cache-Control标头的"max-age"值小于1,这意味着Varnish将永远不会在此URL的缓存中提供内容.

max-age值似乎为:0

这个标题信息

The url we checked: myDomainHere.com
    HTTP/1.1 200 OK
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By:   PHP/5.5.9-1ubuntu4.5
Set-Cookie: PHPSESSID=vgk7db66kh7nce8lpe5789u105; path=/
Expires:    Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:  max-age=60, private, proxy-revalidate
Pragma: no-cache
Vary:   Accept-Encoding,User-Agent
Content-Encoding:   gzip
Content-Type:   text/html
Content-Length: 14192
Accept-Ranges:  bytes
Date:   Sat, 18 Jul 2015 09:31:55 GMT
X-Varnish:  324589322
Age:    0
Via:    1.1 varnish
Connection: keep-alive
Run Code Online (Sandbox Code Playgroud)

我在.htaccess中有这个

 <FilesMatch "\.(js|css)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(html|htm|php)$">
    Header set …
Run Code Online (Sandbox Code Playgroud)

ubuntu caching apache2 varnish http-headers

12
推荐指数
1
解决办法
4340
查看次数

钻石形状与圆角和背景图像

我需要实现这个目标:

钻石图像和圆角

请注意,容器已旋转但图片不是..

现在我做了:

div.img {
  position: relative;
  overflow: hidden;
  width: 320px;
}
div.img img {
  display: block;
  width: 100%
}
div.img span {
  position: absolute;
  content: "";
  width: 75%;
  height: 75%;
  transform: rotate(133deg);
  background: white
}
div.img span.tl {
  top: -36%;
  left: -36%
}
div.img span.bl {
  bottom: -36%;
  left: -36%
}
div.img span.br {
  bottom: -36%;
  right: -36%
}
div.img span.tr {
  top: -36%;
  right: -36%
}
Run Code Online (Sandbox Code Playgroud)
<div class="img">
  <img src="http://lorempixel.com/320/320/nature/?v2s" alt="Pellete">
  <span class="tl"></span>
  <span class="bl"></span>
  <span class="tr"></span>
  <span …
Run Code Online (Sandbox Code Playgroud)

css svg css3 css-shapes

12
推荐指数
2
解决办法
3154
查看次数

将url转换为字符串中的链接,除非它们位于html标记的属性中

我试图转换,从textarea输入($_POST['content']),所有网址链接.

$content = preg_replace('!(\s|^)((https?://)+[a-z0-9_./?=&-]+)!i', ' <a href="$2" target="_blank">$2</a> ', nl2br($_POST['content'])." ");
$content = preg_replace('!(\s|^)((www\.)+[a-z0-9_./?=&-]+)!i', '<a target="_blank" href="http://$2"  target="_blank">$2</a> ', $content." ");
Run Code Online (Sandbox Code Playgroud)

目标链接格式:www.hello.comhttp(s)://(www).hello.com

但这似乎打破任何iframe,图像或类似,

正确的正则表达式如何忽略html标签中的url?

注意:我知道我需要两个表达式; 一个检测没有协议链接(比如www.hello.com,所以我需要预先添加)和另一个检测带协议的URL(所以不需要预先添加).

php regex url preg-replace linkify

11
推荐指数
2
解决办法
9014
查看次数

通过JQuery设置di​​splay:block!important

滚动有一个问题是不想显示其内容

如果我这样做

#callCenter{
    position:fixed;
    z-index:2411 !important;
    display:block !important; /* please note here !important */
    right:110px;

}
Run Code Online (Sandbox Code Playgroud)

它显示,

但如果我这样做:(所以div被隐藏,直到另一个元素被点击)

#callCenter{
    position:fixed;
    z-index:2411 !important;
    right:110px;
}
Run Code Online (Sandbox Code Playgroud)

$('#telefonosCabecera').click(function(){
    $("#callCenter").css('display','block!important'); // or 'block !important'
    alert('done')
});
Run Code Online (Sandbox Code Playgroud)

我没有看到#callCenter但我确实看到了警报

任何想法为什么?

css jquery

10
推荐指数
1
解决办法
3万
查看次数

Cordova并使用命令行设置Android

我正在尝试将我现有的项目从cordova 2.1迁移到最新的3.1,它可以安装到命令行,

我已经安装了Android SDK,

所以:

sudo npm install -g cordova // All good
cordova create hello com.example.hello HelloWorld // All good
cordova platform add android // Then it fires:

Checking Android requirements...
[Error: The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: ]
Run Code Online (Sandbox Code Playgroud)

所以我安装了Macports并尝试:

sudo port install android
Run Code Online (Sandbox Code Playgroud)

Wich日志:

Warning: All compilers are either blacklisted or unavailable; defaulting to first fallback option
Warning: …
Run Code Online (Sandbox Code Playgroud)

sdk android command cordova

10
推荐指数
1
解决办法
2万
查看次数