Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    determine "real" newlines and string "\n"

    Hi!
    I was wondering is there any way PHP could determine when in the text is "real" newline or its a string as "\n" ?
    for example code like this:
    PHP Code:
    <?php
    highlight_string
    ("<?php\n\$text = \"Something\non\nthree lines\";\n?>\n\n");
    highlight_string("<?php\n\$text2 = \"Semething
    on
    three lines\"\n?>"
    );
    ?>
    if u try this code, it will show u exactly identical two stings, even though first one was only using "\n" sting but second was using "real" newlines (or maybe return caret if u prefer)

    so, is there any way to determin it?

    thank you!

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    they are one and the same , they are both newlines "\n"
    the only difference is that on win32 you would expect to find "\r\n" & on *NIX plain old "\n"

    in saying that perhaps try

    if( strpos( $str , "\n" )!==false){ //etc// }
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so, basicaly there is no way I can process through PHP a text file and make from it an identical copy?
    I'm working a script translator, witch has an include for a language script, after witch all needed text for translation is in $lang array and it displays the textarea for each item in the array for translation. Some of the items uses "\n" string and some uses "real" newlines (witch makes easier to read). After translation it saves new file but every "\n" strings become as newlines...if I add a slash to "\n" it will make "real" newlines as strings too...
    so, otherwords, the text that was entered by user will be different after it was saved.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •