0

I have a csv file. In this, I have a bad character : arr‰t. I would this "arret"

I test this : $bodytag = str_replace("‰", "e",$content); doesn't work.

So I search a query which I say : find a word start with "arr" and end with "t" and remplace all the string by "arret". I find a function to get content between but I can't do my query.

    function str_between($str,$start,$end) {
  if (preg_match_all('/' . preg_quote($start) . '(.*?)' . preg_quote($end) . '/',$str,$matches)) {
   return $matches[1];
  }
  // no matches
  return false;
} 

Can you help me?

2 Answers 2

2

Did you try preg_replace('/‰/', 'e', $string); ?
It works for me, with the string "arr‰t", preg_replace returns me "arret"

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, but it works for this preg_replace('/‰/', 'e', "arr‰t"); but not when I do this : $fp=fopen($file,"r"); $content=fread($fp,$sizefile); $bodytag = preg_replace("/‰/", "e",$bodytag); echo $content;
Try to convert $content from ANSI to UTF-8, using iconv then do an echo $content;
When I do echo iconv("UTF-8", "ISO-8859-1", $content), PHP_EOL; The content stop to the first "‰". If I do echo iconv("UTF-8", "ISO-8859-1//IGNORE", $content), PHP_EOL; I see all content and the word is now "arrt"
If $content is ANSI encoded do : iconv("ANSI", "UTF-8", $content) or iconv("Windows-1252", "UTF-8", $content)
By the way, I think it's just an encoding problem, and you'll not need regulars expressions to get an human readable $content.
|
1

My 2 cents: Your file might have encoded characters not supported by the doctype specified. Arret in French has a small "hat" over top of the "e", as in "ê". Check to see if that can be searched and/or replaced as/with ê or ê

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.