Jump to content

find and replace É


lindylex

Recommended Posts

I am trying to do a string find and replace from some xml that I get from a server.

 

 

The character I am trying to find is É  if you can not see it’s chr(201) this is what I have tried with no success.

 

Attempt #1:

 

$patern [0]='/É/';

$patern[1] ='/W/';

$replacements[0] ='XXX';

$replacements[1] ='YYY';

 

echo preg_replace ($patern,$replacements,$finaldata);

 

Attempt #2:

 

strtr($finaldata, chr(201),"VVV");

 

Attempt #3:

 

strtr($finaldata, ‘É’,"VVV");

 

Encoding is encoding="UTF-8"

 

 

Thanks Lex

 

Link to comment
Share on other sites

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<pre>
<?php
### Create string with "LATIN CAPITAL LETTER E WITH ACUTE."
echo $str = 'abc' . pack('C*', 0xc3, 0x89) . '123';
echo '<br>';
### Remove.
echo preg_replace('/\xc9/u', '', $str);
?>
</pre>

Link to comment
Share on other sites

"É" is the UTF-8 encoding for "É." You can see this by going to this letter database, scrolling down to "Search in Unicode character names," entering "e with acute," and clicking "Submit Query." The "U00C9" that appears below the graphic of the character is its code point, and the UTF-8 is below that.

 

What browser are you using the for the example? I see:

 

abcÉ123

abc123

Link to comment
Share on other sites

effigy I am not seeing what you are seeing.  I tried this on Linux using Iceweasel and Windows I.E. 7 and Firefox.

 

I go to this website http://www.eki.ee/letter/

 

And enter the É and I do not see the same output you see.

 

I searched here.

 

“For my own convenience - this input form accepts (hex) utf8 encodings. It does not accept ranges and returns ? if the input is not valid.

Enter Unicode number in UTF-8 (e2 82 ac for Euro):

“ 

And I got nothing.

 

Link to comment
Share on other sites

For my own convenience - this input form accepts (hex) utf8 encodings. It does not accept ranges and returns ? if the input is not valid.

Enter Unicode number in UTF-8 (e2 82 ac for Euro):

 

That's under "Search by Unicode number."

 

scrolling down to "Search in Unicode character names,"

 

 

Link to comment
Share on other sites

The Solution:

 

Effigy, thanks for your help.  I came up with a solution using some valuable information you provided. 

 

The process I used was go to this site http://www.w3schools.com/tags/ref_urlencode.asp

 

Then search for the character I need.  The xc8 in '/\xc8/u' is the hex value for the character I suppose.  But the two characters after the x seem to match the last two of the URL-encode.  Using this chart I got the information I needed to make the find and replace work.

 

function look_for_extended_characters ($the_string_to_convert){

 

$transition=preg_replace('/\xc8/u', '&#200;', $the_string_to_convert); //È  &#200; YES

$transition=preg_replace('/\xc9/u', '&#201;', $transition); //É  &#201;

$transition=preg_replace('/\xc3/u', '&#195;', $transition); //à &#195;

$transition=preg_replace('/\xcf/u', '&#207;', $transition); //Ï  &#207;

$transition=preg_replace('/\xef/u', '&#239;', $transition); //ï  &#239;

$transition=preg_replace('/\xbf/u', '&#191;', $transition); //¿  &#191;

$transition=preg_replace('/\xbd/u', '&#189;', $transition); //½  &#189;

$transition=preg_replace('/\xd4/u', '&#212;', $transition); //Ô  &#212;

$transition=preg_replace('/\xd6/u', '&#214;', $transition); //Ö  &#214;

$transition=preg_replace('/\xc1/u', '&#193;', $transition); //Á  &#214;

$transition=preg_replace('/\xc4/u', '&#196;', $transition); //Ä  &#196;

$transition=preg_replace('/\xc7/u', '&#199;', $transition); //Ç  &#199;

$transition=preg_replace('/\xcc/u', '&#204;', $transition); //Ì  &#204;

 

return $transition;

}

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.