English 中文(简体)
不知道如何做到这一点
原标题:Not sure how to do this regex

在提出以下问题并思考这个问题之后,我认为,我完全需要这一reg。 不知道如何做到这一点。

! [anycharacter](anycharacter) to [anycharacter](anycharacter)

- 原件名称和电文

PHP Markdown Extra - 不许图像

现在,我只是把图像隐藏在允许打上标记的地区。 我要说的是,如果使用标志性图像合成物,图像就得 t。 我实际上宁愿把它变成一个环节,但简单地说,它会错开。 我猜测一个reg栏以检查<代码>!

-edit- right now I am doing a preg_replace of preg_replace( /![/ , "[", $text ); but I still don t think that is the best solution as it will remove the ! even at times there might be another reason ![ comes up. I guess I just need to know how to do replace ![anycharacter](anycharacter) with [anycharacter](anycharacter)

问题回答

This is actually not my code its from http://core.svn.wordpress.org/tags/1.5.1.3/wp-content/plugins/markdown.php but you could use it to prepass your input within your _DoImages_reference_callback($matches) and _DoImages_inline_callback($matches) functions, this however is just a gist.

$text = preg_replace_callback( {
    (               # wrap whole match in $1
      ![
        (.*?)       # alt text = $2
      ]

      [ ]?              # one optional space
      (?:
[ ]*)?       # one optional newline followed by spaces

      [
        (.*?)       # id = $3
      ]

    )
    }xs , 
     _DoImages_reference_callback , $text);

#
# Next, handle inline images:  ![alt text](url "optional title")
# Don t forget: encode * and _

$text = preg_replace_callback("{
    (               # wrap whole match in $1
      !\[
        (.*?)       # alt text = $2
      \]
      \(           # literal paren
        [ \t]*
        <?(S+?)>?  # src url = $3
        [ \t]*
        (           # $4
          ([ "])   # quote char = $5
          (.*?)     # title = $6
          \5       # matching quote
          [ \t]*
        )?          # title is optional
      \)
    )
    }xs",
     _DoImages_inline_callback , $text);




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...