How to change the functions under php?

Source: Internet
Author: User
{Code ...} the $ text parameter in the first function is the code content in the markdown format article, and the content in markdown format is in this form {code ...} if the markdown code block is in this form of {javascript: Code }}}, I want to use the javascript: variable $ la...
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); }

The $ text parameter in the first function is the code content in the markdown format document. The content in the markdown format is in this form.

{Code }}}

If the code block in markdown format is in this form{{{ Javascript: Code }}}
I wantjavascript:Submit the variable $ lang_code to $ codeblock and return the following html content:

$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); }

The $ text parameter in the first function is the code content in the markdown format document. The content in the markdown format is in this form.

{Code }}}

If the code block in markdown format is in this form{{{ Javascript: Code }}}
I wantjavascript:Submit the variable $ lang_code to $ codeblock and return the following html content:

$codeblock = "
$codeblock\n
";

After this

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

Add the following two lines:

$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.