小编Reg*_*dit的帖子

输入包含"/"时的PHP错误

当输入字符串包含"/"符号时,我收到一个PHP错误:

警告:preg_match()[function.preg-match]:未知的修饰符

我该如何解决?

$token = '/<'.$tag.'[^>]*>(.*\b'.$keyword.'\b.*)<\/'.$tag.'>/siU';
if(preg_match($token, &$content, $matches))
{
    $match = 1;
}
return $match;
Run Code Online (Sandbox Code Playgroud)

php preg-match

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

HTML5shiv仅在HEAD部分有效?

为了尽可能快地保存我的网站,我更喜欢在文档末尾加载.js脚本,就在关闭正文标记之前,为HEAD部分保留css.但是,我发现下面的html shiv代码显然只在HEAD部分实例化时才有效.

<!--[if lt IE 9]>
    <script type="text/javascript" 
        src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
    </script>
<![endif]-->
Run Code Online (Sandbox Code Playgroud)

有人知道解决方法吗?

html javascript html5

3
推荐指数
2
解决办法
4404
查看次数

CSS 根据 URL 模式突出显示目录中的活动链接

我有一个 div,其中包含一个 UL 元素以及我的每个页面的目录。

目前,我必须在活动元素(class="active")上硬编码一个特殊的类。但是,我正在尝试通过将 href 与浏览器的当前 URL 匹配来查看是否可以使用 CSS3 来完成这项工作。

例如,如果 toc div 的锚点中的 href 与页面的当前 URL 匹配,则为其添加特殊格式。

示例网址:http : //mysite.com/page-title/2

标记:

<div class="toc">
    <h3>Table of Contents</h3>
    <ul>
        <li><a href="http://mysite.com/page-title/">Part 1</a></li>
        <li><a href="http://mysite.com/page-title/2">Part 2</a></li>
        <li><a href="http://mysite.com/page-title/3">Part 3</a></li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我想对第二个列表项元素应用特殊的 css 格式,因为它的 HREF 模式与 URL 模式匹配“/2”。

如果这不能通过 CSS 实现,如果您能提供 jQuery 代码,我可以将它放在我的 jQuery 脚本中。

css jquery

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

如何通过 CSS 将块级元素转换为内联元素

假设我有以下内容:

<div class="entry">
<p>I want to display <br /><h2>heading level elements like this</h2>
<p> as inline elements on the same line with the text that preceded them as well as...</p>
<p>the text that<br />
<h3>(another heading element)</h3>
<p>, follows them...</p>
</p></p>
</div>
Run Code Online (Sandbox Code Playgroud)

我希望标题元素内联显示在文本中,就像它们只是粗体文本一样,大小与内容相同。

有什么想法 CSS 可以在上面的例子中完成这个而不改变内容吗?

css

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

即使strlen在可接受的范围内,这个正则表达式也会切断字符串中的最后一个单词

$theExcerpt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis'

$theExcerptAppend = (strlen($theExcerpt) > 156) ? '...' : '';
$theExcerpt = preg_replace('/\s+?(\S+)?$/', '', substr($theExcerpt, 0, 156));
$theExcerpt .= $theExcerptAppend;
Run Code Online (Sandbox Code Playgroud)

只要输入短语长度超过156个字符,脚本就可以正常工作.然而,当长度小于156(因为它是在这里154),在最后一个字被放下,即使字符串,包括字,仍低于156.

注意:我不希望字符串在单词的中间终止,但是如果单词的包含不超过156的strlen值,则应该包含它.

php regex preg-replace substr

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

如何处理从php到jQuery ajax错误处理程序的错误消息?

在下面的存根代码中,当调用error:方法时,"errorThrown"变量只返回"object Object".

如何打印出实际文本呢?

jQuery.ajax
({
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    url: myURL,

    success: function(data)
    {       
        if(data['response'] === undefined){
            this.error('No data returned');
        }

        //success code goes here                        
    },

    error: function(errorThrown)
    {
        result += errorThrown;
alert('The error was: '+errorThrown);
        return;
    }
}); 
Run Code Online (Sandbox Code Playgroud)

ajax error-handling jquery

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

从字符串中提取文本到":"冒号,如果存在?

我的应用程序以这种方式存储字符串

Yanone+Kaffeesatz:700
PT+Sans+Narrow
PT+Sans+Narrow:regular,bold
...etc
Run Code Online (Sandbox Code Playgroud)

我需要转换每个字符串,以便最终结果是冒号左边的所有内容(如果有的话).

任何帮助非常感谢.

php string

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

如何在html片段的X段之后插入一串文本?

可能重复:
如何使用PHP解析和处理HTML?

$content = "
<p>This is the first paragraph</p>
<p>This is the second paragraph</p>
<p>This is the third paragraph</p>";
Run Code Online (Sandbox Code Playgroud)

给定上面的一串html内容,我需要在第N段标记之后插入.

我如何解析内容并插入给定的文本字符串,在第2段之后说"你好世界"?

php regex

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

将数组插入指定数组中的指定位置

在下面的数组中,如何将新数组推送到指定位置的$ options数组?

$options = array (
    array( "name" => "My Options",
    "type" => "title"),
    array( "type" => "open"),

    array("name" => "Test",
    "desc" => "Test",
    "id" => $shortname."_theme",
    "type" => "selectTemplate",
    "options" => $mydir ),

//I want the pushed array inserted here.

    array("name" => "Test2",
    "desc" => "Test",
    "id" => "test2",
    "type" => "test",
    "options" => $mydir ),

    array( "type" => "close")
    );

    if(someCondition=="met")
    {
    array_push($options, array( "name" => "test",
        "desc" => "description goes here",
        "id" => "testMet",
        "type" => "checkbox", …
Run Code Online (Sandbox Code Playgroud)

php arrays

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

致命错误:呼叫时间传递参考

我在注释行上收到此错误.知道为什么吗?

Fatal error: Call-time pass-by-reference has been removed in myfile.php on line 301
Call Stack
#   Time    Memory  Function    Location
1   0.0002  245352  {main}( )   ../plugins.php:0
2   0.3016  7149968 plugin_sandbox_scrape( )    ../plugins.php:156
Run Code Online (Sandbox Code Playgroud)

代码如下......

function rseo_doTheParse($tag, $post){
    //headings
    $keyword = rseo_sanitize3(trim(strtolower(rseo_getKeyword($post))));
    $content = rseo_sanitize3($post->post_content);
    $match = 0;

            $token = '/<'.$tag.'[^>]*>(.*\b'.$keyword.'\b.*)<\/'.$tag.'>/siU';
            if(preg_match($token, &$content, $matches)) //THIS IS LINE 301
            {
                $match = 1;
            }
            return $match;
        }
Run Code Online (Sandbox Code Playgroud)

php

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

如何绕过 PHP 脚本中的语法错误?

在我的 WordPress 博客上,每当我遇到 PHP 错误时,它都会破坏网站并显示带有 PHP 错误的白页。

例如:

解析错误:语法错误,意外的“;” 在...

我可以修复错误。但是,我不希望用户在我这样做时看到损坏的网站。我可以启用一个设置来抑制错误(或更优雅地处理错误)并继续解析 PHP 的其余部分吗?

php error-handling

-1
推荐指数
1
解决办法
3934
查看次数

如何将Google网络字体动态加载到数组中?

我想提取整个Google Web字体集合的提要,并将它们收集到具有此结构的数组中(font collection => font name):

<?php
$googleFonts = array
(
"" => "None",
"Abel"=>"Abel",
"Abril Fatface"=>"Abril Fatface",
"Aclonica"=>"Aclonica",
"Actor"=>"Actor",
"Astloch:regular,bold"=>"Astloch (plus bold)",
//...etc
)
?>
Run Code Online (Sandbox Code Playgroud)

是否存在以这种方式获取字体的API?

php webfonts

-1
推荐指数
1
解决办法
3445
查看次数