Octal Notation in Regex

I recently needed to replace the non-standard extended characters that ms-word uses for quotes in over 80 pages. The octal notation available in regular expressions proved to be very helpful. To use octal in a regular expression just escape the three number code like \200.
[code lang="php"]
#!/usr/bin/php -q
for($id = 1; $id<82; $id++) {
$text=mysql_result($result,0,"content");
$new_text = ereg_replace("â\200\234","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\235","\"",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\223","-",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\231","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200\230","'",$text);
$text = $new_text;
$new_text = ereg_replace("â\200","",$text);
$text = $new_text;
$new_text = ereg_replace("â","\"",$text);
$text = $new_text;
$new_text = ereg_replace("\r\n","\n",$text);
$escaped_text = mysql_escape_string($text);
}
?>
[/code]


 
 
 

Leave a Reply


Mmm, I am really impressed with NOVO coffee. Very good! Maybe it's just because I've been drinking the Folgers coffee at the office.

Just saved $290 by changing the damn radiator myself

Doh, I ran out of propane halfway through a brew session. That added an extra hour to an already long brew day.

Follow me on Twitter