Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I use BBCode Helper. helper code:

function parse_bbcode($str = ''){

$find = array(
  "'\[v\](.*?)\[/v\]'is"
);

$replace = array(
  '<video>\1</video>'
);

return preg_replace($find, $replace, $str);

}

controller:

$this->load->helper('bbcode');

$data['news'] = $this->news_model->get_news($config['per_page'], $this->uri->segment(3, 1));

foreach ($data['news'] as $key=>$val)
{
  parse_bbcode($data['news'][$key]['description']); 
}

for example i want to replace [v]vid[/v] to vid. replacement does not work (nothing happens). what I did wrong?

share|improve this question
Does not work how? What do you expect to happen? – Almo Feb 18 at 17:06
oh sorry, i forgot to say what i want. i updated first post. – Vitaliy Feb 18 at 17:15
add comment (requires an account with 50 reputation)

1 Answer

up vote 0 down vote accepted

Your regex is wrong.

This works:

$video = "[v]testvid.swf[/v]";

$re = '/\[v](.+)\[\/v\]/i';

$replace = '<video>\1</video>';

echo htmlspecialchars(preg_replace($re, $replace, $video));

Outputs:

<video>testvid.swf</video>

http://regexpal.com/ is a good resource for working out regex issues.

share|improve this answer
don't works. maybe somthing with foreach? – Vitaliy Feb 18 at 19:03
1  
Impossible to tell without looking at the contents of $data['news']. Here's a working example with an array: codepad.viper-7.com/bMrZmi – stormdrain Feb 18 at 19:14
$data['news] it's array of posts. every post contain id, title, description. – Vitaliy Feb 18 at 20:36
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.