4 sty 2013

Usunięcie tagów html z tekstu

Usunięcie tagów html z tekstu

$art_text = preg_replace("/(align|class|style|clear)\=\"([^\"]*)\"/", '', $art_text);
$art_text = strip_tags($art_text, '<p><br><strong><b><em><u><strike>');
echo $art_text;
4 sty 2013

Zamiana przecinka na spacje przy użyciu regexp_replace

select
  a_title,
  regexp_replace(a_title, ' +', ' ', 'g')
from articles
where
  a_status = 't'
  and a_title ~ ' '
update articles
set
  a_title = regexp_replace(a_title, ',', ' ')
where
  a_status = 't'
  and a_title ~ ','
update articles
set
  a_title = regexp_replace(a_title, ' +', ' ', 'g')
where
  a_status = 't'
  and a_title ~ ' '
4 sty 2013

Wyrażenie regularne i preg_match

$test='http://kody.wig.pl/strony-stare-2006_11-all.html';
$test='http://kody.wig.pl/strony-nowe-2012_11-1233.html';
echo $test;
preg_match("/(-(?P([0-9]+|all)))?\.html$/", $test, $back);
print_r($back);