albertopriore
albertopriore

Reputation: 614

PHP regex issue

I was trying to use preg_replace on a string but I obtain a wrong result.

$string = "Da venerdì 26 agosto a lunedì 5 settembre 2011";
$string = preg_replace('/\p{L}+/s','',$string);

should return " 26 5 2011 " but it returns " ¬ 26 ¬ 5 2011 "

*note in my local php server on Windows XP all works fine but in my remote php server on Debian it retunrs me the wrong string

Can you help me?

Upvotes: 1

Views: 85

Answers (1)

Quamis
Quamis

Reputation: 11087

You want to extract number from the string from what i see.

  • you have some encoding issues with your texts. Those chars should be UTF8, but they somehow got screwed up. Maybe you have them from the DB and the DB tables are not UTF8?
  • If you want to extract all numbers, then dont assume that a string is composed only from letters and numbers. Look at http://www.regular-expressions.info/unicode.html for a list of supported character types
  • use preg_replace("/[\s]+/", ' ', preg_replace('/[^0-9\s]/',' ',$string)); to remove anything non-number from the string, and leave only one separator space between numbers

Upvotes: 2

Related Questions