Welcome Guest, Not a member yet? Register   Sign In
[Solved] Using preg_replace_callback with a href
#1

(This post was last modified: 11-01-2016, 05:19 PM by wolfgang1983.)

In my preg_replace_callback I can allow some elements to be showing in preview using the preg_replace_callback

How ever when the user has typed in a link lets say <a href="http://www.example.com">Example</a>

The preview will only put out <a href="http://www.example.com">Example

Is there any way I can integrate this


PHP Code:
preg_replace("~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~","<a href=\"\\0\">\\0</a>"$string


Into the code below


PHP Code:
public function preview() {
    $data = array('success' => false'question' => '');

    if ($_POST) {

        $string $this->input->post('question');

           $match = array(
            '<' => '&lt;',
            '>' => '&gt;',
        );

        $new_data preg_replace_callback("#</?(pre|code|h1|h2|h3|h4|h5|h6|b|strong|i|u|hr)>|[<>]#", function ($match) {
            return $match[0] == '<' '&lt;' : ($match[0] == '>' '&gt;' $match[0]);
        }, $string);

        $data['question'] = parse_smileys($new_database_url('assets/img/smiley'));
        $data['success'] = true;
    }

    $this->output
           
->set_content_type('application/json')
        ->set_output(json_encode($data));

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Using preg_replace_callback with a href - by wolfgang1983 - 10-31-2016, 03:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB