Can't remove weird return character / line ending in PHP












0














I have a PHP function that generates an XML file from my data. Some of which was submitted via textarea fields.



When I create the XML file the textarea fields are displaying with an unusual carriage return at the end of the value. I've tried removing with the following methods, none of which do anything.



trim($value)
str_replace( "n", "", $value)
str_replace( "r", "", $value)
str_replace( "nr", "", $value)
str_replace( "rn", "", $value)
preg_replace('/ss+/', ' ', $value)


even tried strip_tags($value) and html_entity_decode($value) in case it was something weird i could strip out.



One thing that did remove it was removing all but alphanumeric characters via a regex but thats no use since my users will want to use a lot of characters like dashes, brackets, single and double quotes, etc.



Are there any other methods of removing weird characters like this? Or any other strange carriage returns that I can remove via code?










share|improve this question






















  • Try preg_replace('/R+/', ' ', $value)
    – Wiktor Stribiżew
    Nov 19 at 21:41










  • Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
    – Matt Preston
    Nov 19 at 21:44










  • Can you paste that char here in the question body?
    – Wiktor Stribiżew
    Nov 19 at 21:45










  • No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
    – Matt Preston
    Nov 19 at 21:48






  • 1




    Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
    – Matt Preston
    Nov 20 at 15:21
















0














I have a PHP function that generates an XML file from my data. Some of which was submitted via textarea fields.



When I create the XML file the textarea fields are displaying with an unusual carriage return at the end of the value. I've tried removing with the following methods, none of which do anything.



trim($value)
str_replace( "n", "", $value)
str_replace( "r", "", $value)
str_replace( "nr", "", $value)
str_replace( "rn", "", $value)
preg_replace('/ss+/', ' ', $value)


even tried strip_tags($value) and html_entity_decode($value) in case it was something weird i could strip out.



One thing that did remove it was removing all but alphanumeric characters via a regex but thats no use since my users will want to use a lot of characters like dashes, brackets, single and double quotes, etc.



Are there any other methods of removing weird characters like this? Or any other strange carriage returns that I can remove via code?










share|improve this question






















  • Try preg_replace('/R+/', ' ', $value)
    – Wiktor Stribiżew
    Nov 19 at 21:41










  • Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
    – Matt Preston
    Nov 19 at 21:44










  • Can you paste that char here in the question body?
    – Wiktor Stribiżew
    Nov 19 at 21:45










  • No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
    – Matt Preston
    Nov 19 at 21:48






  • 1




    Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
    – Matt Preston
    Nov 20 at 15:21














0












0








0







I have a PHP function that generates an XML file from my data. Some of which was submitted via textarea fields.



When I create the XML file the textarea fields are displaying with an unusual carriage return at the end of the value. I've tried removing with the following methods, none of which do anything.



trim($value)
str_replace( "n", "", $value)
str_replace( "r", "", $value)
str_replace( "nr", "", $value)
str_replace( "rn", "", $value)
preg_replace('/ss+/', ' ', $value)


even tried strip_tags($value) and html_entity_decode($value) in case it was something weird i could strip out.



One thing that did remove it was removing all but alphanumeric characters via a regex but thats no use since my users will want to use a lot of characters like dashes, brackets, single and double quotes, etc.



Are there any other methods of removing weird characters like this? Or any other strange carriage returns that I can remove via code?










share|improve this question













I have a PHP function that generates an XML file from my data. Some of which was submitted via textarea fields.



When I create the XML file the textarea fields are displaying with an unusual carriage return at the end of the value. I've tried removing with the following methods, none of which do anything.



trim($value)
str_replace( "n", "", $value)
str_replace( "r", "", $value)
str_replace( "nr", "", $value)
str_replace( "rn", "", $value)
preg_replace('/ss+/', ' ', $value)


even tried strip_tags($value) and html_entity_decode($value) in case it was something weird i could strip out.



One thing that did remove it was removing all but alphanumeric characters via a regex but thats no use since my users will want to use a lot of characters like dashes, brackets, single and double quotes, etc.



Are there any other methods of removing weird characters like this? Or any other strange carriage returns that I can remove via code?







php regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 21:39









Matt Preston

245




245












  • Try preg_replace('/R+/', ' ', $value)
    – Wiktor Stribiżew
    Nov 19 at 21:41










  • Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
    – Matt Preston
    Nov 19 at 21:44










  • Can you paste that char here in the question body?
    – Wiktor Stribiżew
    Nov 19 at 21:45










  • No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
    – Matt Preston
    Nov 19 at 21:48






  • 1




    Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
    – Matt Preston
    Nov 20 at 15:21


















  • Try preg_replace('/R+/', ' ', $value)
    – Wiktor Stribiżew
    Nov 19 at 21:41










  • Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
    – Matt Preston
    Nov 19 at 21:44










  • Can you paste that char here in the question body?
    – Wiktor Stribiżew
    Nov 19 at 21:45










  • No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
    – Matt Preston
    Nov 19 at 21:48






  • 1




    Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
    – Matt Preston
    Nov 20 at 15:21
















Try preg_replace('/R+/', ' ', $value)
– Wiktor Stribiżew
Nov 19 at 21:41




Try preg_replace('/R+/', ' ', $value)
– Wiktor Stribiżew
Nov 19 at 21:41












Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
– Matt Preston
Nov 19 at 21:44




Nope. still there I'm afraid. its the weirdest thing! Can't figure out what return character it would be. Thank you for your quick response though.
– Matt Preston
Nov 19 at 21:44












Can you paste that char here in the question body?
– Wiktor Stribiżew
Nov 19 at 21:45




Can you paste that char here in the question body?
– Wiktor Stribiżew
Nov 19 at 21:45












No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
– Matt Preston
Nov 19 at 21:48




No i just tried and the content appears without any return after the content. here is anyway. The weird returns are just after the "content." <label>test 1: </label><some_data>test content. </some_data> <label>test 2: </label><some_data>test content.</some_data>
– Matt Preston
Nov 19 at 21:48




1




1




Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
– Matt Preston
Nov 20 at 15:21




Hi, hopefully I have. I upvoted it yesterday but forgot to accept.
– Matt Preston
Nov 20 at 15:21












2 Answers
2






active

oldest

votes


















2














You may use



$value = preg_replace('/R+/u', ' ', $value)


Here, R matches any Unicode line break sequence.



Also, see the /u modifier reference:




u (PCRE_UTF8)

This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.







share|improve this answer





























    0














    I've had similar cases. In my case, there was a non-breaking-space unicode character which looked like a space, but wasn't.



    What you could do it iteracte over all the characters in the string, and inspect them one by one so see what's odd. This will probably not solve your problem directly, but at least help you get to the solution I hope.



    for( $i = 0; $i < strlen($value); $i++ ) {
    $chr = $value[$i];
    echo "{$i}: [$chr}] [".ord($chr)."];n";
    }





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383019%2fcant-remove-weird-return-character-line-ending-in-php%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      You may use



      $value = preg_replace('/R+/u', ' ', $value)


      Here, R matches any Unicode line break sequence.



      Also, see the /u modifier reference:




      u (PCRE_UTF8)

      This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.







      share|improve this answer


























        2














        You may use



        $value = preg_replace('/R+/u', ' ', $value)


        Here, R matches any Unicode line break sequence.



        Also, see the /u modifier reference:




        u (PCRE_UTF8)

        This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.







        share|improve this answer
























          2












          2








          2






          You may use



          $value = preg_replace('/R+/u', ' ', $value)


          Here, R matches any Unicode line break sequence.



          Also, see the /u modifier reference:




          u (PCRE_UTF8)

          This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.







          share|improve this answer












          You may use



          $value = preg_replace('/R+/u', ' ', $value)


          Here, R matches any Unicode line break sequence.



          Also, see the /u modifier reference:




          u (PCRE_UTF8)

          This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern and subject strings are treated as UTF-8.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 at 22:16









          Wiktor Stribiżew

          306k16125202




          306k16125202

























              0














              I've had similar cases. In my case, there was a non-breaking-space unicode character which looked like a space, but wasn't.



              What you could do it iteracte over all the characters in the string, and inspect them one by one so see what's odd. This will probably not solve your problem directly, but at least help you get to the solution I hope.



              for( $i = 0; $i < strlen($value); $i++ ) {
              $chr = $value[$i];
              echo "{$i}: [$chr}] [".ord($chr)."];n";
              }





              share|improve this answer


























                0














                I've had similar cases. In my case, there was a non-breaking-space unicode character which looked like a space, but wasn't.



                What you could do it iteracte over all the characters in the string, and inspect them one by one so see what's odd. This will probably not solve your problem directly, but at least help you get to the solution I hope.



                for( $i = 0; $i < strlen($value); $i++ ) {
                $chr = $value[$i];
                echo "{$i}: [$chr}] [".ord($chr)."];n";
                }





                share|improve this answer
























                  0












                  0








                  0






                  I've had similar cases. In my case, there was a non-breaking-space unicode character which looked like a space, but wasn't.



                  What you could do it iteracte over all the characters in the string, and inspect them one by one so see what's odd. This will probably not solve your problem directly, but at least help you get to the solution I hope.



                  for( $i = 0; $i < strlen($value); $i++ ) {
                  $chr = $value[$i];
                  echo "{$i}: [$chr}] [".ord($chr)."];n";
                  }





                  share|improve this answer












                  I've had similar cases. In my case, there was a non-breaking-space unicode character which looked like a space, but wasn't.



                  What you could do it iteracte over all the characters in the string, and inspect them one by one so see what's odd. This will probably not solve your problem directly, but at least help you get to the solution I hope.



                  for( $i = 0; $i < strlen($value); $i++ ) {
                  $chr = $value[$i];
                  echo "{$i}: [$chr}] [".ord($chr)."];n";
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 at 22:03









                  JoerT

                  374




                  374






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383019%2fcant-remove-weird-return-character-line-ending-in-php%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                      Alcedinidae

                      Can an atomic nucleus contain both particles and antiparticles? [duplicate]