Search and replace double quotes

  • 15 years ago

    Hi,
    I'm trying to find a way to change characters like the quote, double quote and the french accent characters (é, à, ç, ect) into html entities. The reason I can't use the htmlentities function is that I want to change everything that are not inside HTML tags


    So this:
    $s = "this is a <a href=\"link.php?i=1#a\" name=\"École (school in french)\">link to the "school"</a>";


    Should end up something like:
    "this is a <a href=\"link.php?i=1#a\" name=\"École (school in french)\">link to the "school"</a>";



    The changes from the french characters to the html entities is easy since I just run a find and replace, but the quotes are giving me a real problem. As you can see I don't want any change in the tag.


    I thing the best way to go is regex (if you have anything else to propose I would apreciate it). The thing is that I'm really new at regex, this is what I have ended up with:

    Code:
       $patterns[] = "/(<[^>]*>)?\"/";
       $replaces[] = "$1"";
       $retour =  preg_replace($patterns, $replaces, $text);

    But this is not working, it changes every " even inside the tag.



    -- The content will be inputed by users.



    Thank you for any help you can give me,
    Santa Clown

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Brevity is the soul of wit” - Shakespeare