标签: preg-replace

PHP preg_replace:帮帮我grok(?= :)

另一个问题中,有以下几行:

$value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT';
$value = preg_replace('/(^.+?)(?=:)/e', "strtolower('\\1')", $value);
// yields 'x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT'
Run Code Online (Sandbox Code Playgroud)

(?=:)位表示搜索冒号,它必须.但是,我不明白那个特殊的语法,用?=.究竟是怎么回事?

php regex preg-replace

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

使用preg_replace删除URL中的&和空格

我试图删除空格和&在URL中,并用 - 替换它.到目前为止,以下工作:

preg_replace('/\s+/', '-', $page->label) // whitepace gets replaced with -    
preg_replace('/\&/', '-', $page->label) // & gets replaced with - 
Run Code Online (Sandbox Code Playgroud)

我想在一行中有这个,但我无法结合2.任何人都可以帮忙吗?非常感谢你提前.

php regex preg-replace

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

PHP:preg替换日期时间

我如何用preg_replace替换这种格式'Fri Mar 23 15:21:08 2012'的日期/时间?这种格式的日期在我的文本中出现几次,我需要用当前时间/日期替换它.

谢谢,

克里斯

php preg-replace

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

PHP ereg_replace允许空格

使用preg_replace我想只允许使用字母数字和空格,但 ereg_replace("[^A-Za-z0-9\w\] 删除所有空格.

我该怎么办才能解决它?

提前致谢

php preg-replace

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

我想从字符串中删除特殊符号,句点,连字符,下划线和数字 - PHP

我的要求是从字符串中删除除下划线之外的所有特殊符号.

我在用..

$string = 'text-text_text+text@text(text)text&text.text*text\text/text';
$columnName = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '_', $string);
Run Code Online (Sandbox Code Playgroud)

输出:

text-text_text_text_text(text)text&text.text_text_text_text
Run Code Online (Sandbox Code Playgroud)

但它不删除句号,符号,括号和破折号.在创建这个正则表达式时,我感到无助.请帮忙..

php regex string preg-replace

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

允许" - "和"." 在preg_replace中

$username = preg_replace("/[^\p{L}|\p{N}]/u", "", html_entity_decode($username));
Run Code Online (Sandbox Code Playgroud)

这允许"字母"和"数字" $username,删除其他一切.

但是我怎样才能在混合中使用 "."点符号呢?也会"-"很好.

非常感谢你!

php regex preg-replace preg-match

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

PHP preg_replace替代方案

由于弃用,我们目前在我们的网站上收到preg_replace错误消息.

我们的代码如下:

$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $data);
Run Code Online (Sandbox Code Playgroud)

有关如何用非弃用代码替换它的任何建议?

php preg-replace deprecated

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

为什么在Laravel中提交帖子表单时会出现preg_replace()错误?

我已经构建了一个简单的应用程序laravel 4.我有脚手架设置添加帖子似乎工作正常.我已经设置了Stapler和图片上传包.当我设置使用单张图片上传时,它非常好,它的魅力.我最近看过这里的文档

它声明你可以进行多次上传,所以我按照文档中的说明去做.这是我的编码页面:

Post.php模型:

<?php

class Post extends Eloquent {
    use Codesleeve\Stapler\Stapler;
    protected $guarded = array();

    // A user has many profile pictures.
    public function galleryImages(){
        return $this->hasMany('GalleryImage');
    }

    public static $rules = array(
        'title' => 'required',
        'body' => 'required'
    );

    public function __construct(array $attributes = array()) {
    $this->hasAttachedFile('picture', [
        'styles' => [
            'thumbnail' => '100x100',
            'large' => '300x300'
        ],
        // 'url' => '/system/:attachment/:id_partition/:style/:filename',
        'default_url' => '/:attachment/:style/missing.jpg'
    ]);

    parent::__construct($attributes);
    }

}
Run Code Online (Sandbox Code Playgroud)

PostsController.php

/**
     * Store a newly created …
Run Code Online (Sandbox Code Playgroud)

php preg-replace laravel laravel-4

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

除了具有远程链接的锚之外,我怎么能strip_tags?

如何用链接替换标签的内容

$str = 'This <strong>string</strong> contains a <a href="/local/link.html">local link</a>
        and a <a href="http://remo.te/link.com">remote link</a>';
$str = strip_tags($str,'<a>'); // strip out the <strong> tag
$str = ?????? // how can I strip out the local link anchor tag, but leave the remote link?
echo $str;
Run Code Online (Sandbox Code Playgroud)

期望的输出:

This string contains a local link and a <a href="http://remo.te/link.com">remote link</a>
Run Code Online (Sandbox Code Playgroud)

或者,更好的是,用其url替换远程链接的内容:

This string contains a local link and a http://remo.te/link.com
Run Code Online (Sandbox Code Playgroud)

我怎样才能达到最终输出?

php replace preg-replace str-replace strip-tags

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

PHP与0交换0

我得到以下变量

$inputMobile = $_POST["inputMobile"];
Run Code Online (Sandbox Code Playgroud)

现在数字可以有多种方式,例如

07714....
+447714...
00447714...
Run Code Online (Sandbox Code Playgroud)

我需要做的是确保无论我得到什么数字,我都会将其更改为以+44开头.我有这样的事情

$inputMobile = $_POST["inputMobile"];
    if (substr($inputMobile, 0, 1) === '+44') { 
        $inputMobile = $_POST["inputMobile"];
    }
    else {
        $inputMobile = preg_replace('/^0?/', '+44', $inputMobile);
    }
Run Code Online (Sandbox Code Playgroud)

问题是,如果我给它一个像+447714的数字,它返回+ 44 + 44714.

我怎么能阻止这种情况发生?

谢谢

php regex preg-replace phone-number

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