php - Preg_replace for encoding -


I'm really bad in the regex expression,

the code below which I saw in my current application Php's but it does not really understand what it's doing.

preg_replace ('/ (& lt;? Xml [^ & gt;] *) encoding = ["\'] ([^>" \ '] *) ? ["\ '] ([^ & Gt;] *? & Gt;) /', '$ 1 encoding =' '. $ Encoding.'" $ 3 ', $ content); Return $ content;

If a specialist can share some information that would be really good.

Update

It is trying to run but I am not working here. I am not here anything ..

  $ encoding = 'utf-32'; $ Content = '& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RSS version = "2.0" xmlns: media = "http://search.yahoo.com/mrss/" xmlns: atom = "http://www.w3.org/2005/ atom" & gt encoding = ["\ '] ([^> "\'] *) [& Lt; Channel & gt; & Lt; / Channel & gt; Eqo preg_replace ('/ (& lt ;? xml [^ & gt; \'] ([^ & gt;] *? & Gt;) / ',' $ 1 encoding = ''. $ Encoding. '"$ 3 ', $ Content);  

Update

It may look stupid .. but it was working ... because it XML tag is why I need it to be displayed in Chrome and it will display it ...

Thank you .. Specifically M42

is concerned, Mona

This will replace the existing encoding in the file, in which The variable is contained in the example $ encoding

example:

   

( $ encoding = 'UTF-8'; ) Assume:

  & Lt ;? Xml blah blah encoded = "UTF-8" blah blah? & Gt;  

$ 1 includes: & lt; xml Blah blah
$ 3 includes: blah blah & gt;
The result is the integration of $ 1 , encode = "UTF-8" and $ 3.

Regex explanation:

  Regular expression: (& lt ;? Xml [^ & gt;] *) encoding = ["\ ' ] ([^> "\ '] *)? ["\ '] ([^ & Gt; *? & Gt;) matches as follows: NODE explanation ------------------------- --------------------------------------------- (Group and capture \ 1: --------------------------------------------- for - ----------------------- & lt;? '& Lt;' (optional (maximal possible match) ------- --- ----------------------------------------------- --- ---------- xml 'xml' --------------------------------- --- ---------------------------------- [^ & gt;] * Any character except: '& Gt;' (0 or more time (possibly matching to the highest amount)) ------------------------------ ----------- -----------------------------) End of \ 1----- ----------- -------------------------------------- ------------ ---- encoding = 'encoding =' ---------------------------- ------------ ------------------------------ ["\ '] any of Character:' '' ',' \ '" --- ------------------------------------ -------------- ----------------- (group and occupy \ 2 (optional (potentially matching the highest amount) )): --------------- -------------------------------- ------------------ ----- [^ & gt; Any character except '\'] *: '', '' ',' \ '(0 or more times (potentially matching the maximum amount)) ------ ------ -------------------------------------------- ------ --------)? \ 2 End (note: because you are using Quantifiers on this capture, only the last repetition of the captured pattern will be stored in \ 2) ---- -------------- ------------------------------------ -------------- - Any character of ["\ ']:' '', '' '------------------ ------------- ------------------------------------- - (Group to capture and \ 3: --- ----------------------------------- --- ------------ ----------------- [^ & gt;] * * Excluding Any Character: '& gt;' (0 Or more often (possibly matching with the least amount of time)) ----- ------------------------------- ------------------- --------------- & gt; '& gt;' -------- --------------------- ----------------------------- ------------) End of \ 3 ---- ----------------------------- --------------------- ------------- ---  
< / Html>

Comments