Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14115

Using preg_replace_callback with a href

$
0
0
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(
            '<' => '<',
            '>' => '>',
        );

        $new_data preg_replace_callback("#</?(pre|code|h1|h2|h3|h4|h5|h6|b|strong|i|u|hr)>|[<>]#", function ($match) {
            return $match[0] == '<' '<' : ($match[0] == '>' '>' $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));


Viewing all articles
Browse latest Browse all 14115

Trending Articles