How do I change the function under PHP?

Source: Internet
Author: User
protected function Docodeblocks ($text) {# # # Process Markdown ' ' Blocks. # preg_match ('/\{\{\{/i ', $text, $_m_c_open); Preg_match ('/\}\}\}/i ', $text, $_m_c_close); if (count ($_m_c_open) = = count ($_m_c_close)) {$text = Preg_replace_callback ('/\{\{\{[\n]* (. *?) \}\}\}/is ', Array (& $this, ' _docodeblocks_callback '), $text); } return $text; } protected function _docodeblocks_callback ($matches) {$codeblock = $matches [1]; $codeblock = $this->outdent ($codeblock); $codeblock = Htmlspecialchars ($codeblock, ent_noquotes); # trim leading newlines and trailing newlines $codeblock = preg_replace ('/\a\n+|\n+\z/', ' ', $codeblock); $codeblock = str_replace (Array (' & ', ' \ t ', '), Array (' & ', ', '), $codeblock); $codeblock = "
$codeblock \ n
"; return $this->hashblock ($codeblock); }

这第一个个函数中的参数$text是markdown格式文章中的代码内容,markdown 格式的内容是这种形式的

{{{ 代码 }}}

如果markdown格式的代码块是这种形式的 {{{javascript: 代码}}}
我想把javascript:用变量$lang_code的形式提交给$codeblock里面,之后返回下面的html内容:

$codeblock = "
$codeblock\n
";

Reply content:

protected function Docodeblocks ($text) {# # # Process Markdown '' Blocks. # preg_match ('/\{\{\{/i ', $text, $_m_c_open); Preg_match ('/\}\}\}/i ', $text, $_m_c_close); if (count ($_m_c_open) = = count ($_m_c_close)) {$text = Preg_replace_callback ('/\{\{\{[\n]* (. *?) \}\}\}/is ', Array (& $this, ' _docodeblocks_callback '), $text); } return $text; } protected function _docodeblocks_callback ($matches) {$codeblock = $matches [1]; $codeblock = $this->outdent ($codeblock); $codeblock = Htmlspecialchars ($codeblock, ent_noquotes); # trim leading newlines and trailing newlines $codeblock = preg_replace ('/\a\n+|\n+\z/', ' ', $codeblock); $codeblock = str_replace (Array (' & ', ' \ t ', '), Array (' & ', ', '), $codeblock); $codeblock = "
$codeblock \ n
"; return $this->hashblock ($codeblock); }

这第一个个函数中的参数$text是markdown格式文章中的代码内容,markdown 格式的内容是这种形式的

{{{ 代码 }}}

如果markdown格式的代码块是这种形式的 {{{javascript: 代码}}}
我想把javascript:用变量$lang_code的形式提交给$codeblock里面,之后返回下面的html内容:

$codeblock = "
$codeblock\n
";

behind this

  # trim leading newlines and trailing newlines$codeblock = preg_replace ('/\a\n+|\n+\z/', ', $codeblock);  

Add the following two lines to try:

  $lang _pos = Strpos ($codeblock, ":"); $lang _code_pre = substr ($codeblock, 3 , $lang _pos-3);        Switch ($lang _code_pre) {case ' php ': $lang _code = "PHP";    Break        Case ' JavaScript ': $lang _code = "JavaScript";    Break        Default: $lang _code = "Default value"; Break }  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.