how to remove specific characters and special characters from a string in php [closed]










0















I Have a string data coming from for loop, i want to remove specific characters and special characters from a string.Please find below my data.



["rn rn 300518</departureDate>rnttttttttt
rnttttttttt rn </availabilityDetails>rn
rn HYD</cityAirport>rn </departureLocationInfo>rn
rn DXB</cityAirport>rn </arrivalLocationInfo>rn
</availabilityProductInfo>702</orderClassesByCabin>
</cabinOption>",44,"AUHOT3116"]


i tried str_replace and trim functions in php but not working.I want out put from this string like below.



300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-
cityAirport-arrivalLocationInfo-availabilityProductInfo-702-
orderClassesByCabin-44-AUHOT3116


simply remove all ,r,n,t from this string. Can any one will help me.I was tried not getting result.Thanks advance..










share|improve this question















closed as off-topic by Paul, Rob, Billal Begueradj, lucascaro, Devon_C_Miller Nov 12 '18 at 5:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Paul, Rob, Billal Begueradj
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 5





    Possible duplicate of Remove excess whitespace from within a string

    – Stephen Lake
    Nov 11 '18 at 14:27















0















I Have a string data coming from for loop, i want to remove specific characters and special characters from a string.Please find below my data.



["rn rn 300518</departureDate>rnttttttttt
rnttttttttt rn </availabilityDetails>rn
rn HYD</cityAirport>rn </departureLocationInfo>rn
rn DXB</cityAirport>rn </arrivalLocationInfo>rn
</availabilityProductInfo>702</orderClassesByCabin>
</cabinOption>",44,"AUHOT3116"]


i tried str_replace and trim functions in php but not working.I want out put from this string like below.



300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-
cityAirport-arrivalLocationInfo-availabilityProductInfo-702-
orderClassesByCabin-44-AUHOT3116


simply remove all ,r,n,t from this string. Can any one will help me.I was tried not getting result.Thanks advance..










share|improve this question















closed as off-topic by Paul, Rob, Billal Begueradj, lucascaro, Devon_C_Miller Nov 12 '18 at 5:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Paul, Rob, Billal Begueradj
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 5





    Possible duplicate of Remove excess whitespace from within a string

    – Stephen Lake
    Nov 11 '18 at 14:27













0












0








0








I Have a string data coming from for loop, i want to remove specific characters and special characters from a string.Please find below my data.



["rn rn 300518</departureDate>rnttttttttt
rnttttttttt rn </availabilityDetails>rn
rn HYD</cityAirport>rn </departureLocationInfo>rn
rn DXB</cityAirport>rn </arrivalLocationInfo>rn
</availabilityProductInfo>702</orderClassesByCabin>
</cabinOption>",44,"AUHOT3116"]


i tried str_replace and trim functions in php but not working.I want out put from this string like below.



300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-
cityAirport-arrivalLocationInfo-availabilityProductInfo-702-
orderClassesByCabin-44-AUHOT3116


simply remove all ,r,n,t from this string. Can any one will help me.I was tried not getting result.Thanks advance..










share|improve this question
















I Have a string data coming from for loop, i want to remove specific characters and special characters from a string.Please find below my data.



["rn rn 300518</departureDate>rnttttttttt
rnttttttttt rn </availabilityDetails>rn
rn HYD</cityAirport>rn </departureLocationInfo>rn
rn DXB</cityAirport>rn </arrivalLocationInfo>rn
</availabilityProductInfo>702</orderClassesByCabin>
</cabinOption>",44,"AUHOT3116"]


i tried str_replace and trim functions in php but not working.I want out put from this string like below.



300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-
cityAirport-arrivalLocationInfo-availabilityProductInfo-702-
orderClassesByCabin-44-AUHOT3116


simply remove all ,r,n,t from this string. Can any one will help me.I was tried not getting result.Thanks advance..







php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 '18 at 14:23









Daniel Larsson

5372419




5372419










asked Nov 11 '18 at 14:07









NiruNiru

14




14




closed as off-topic by Paul, Rob, Billal Begueradj, lucascaro, Devon_C_Miller Nov 12 '18 at 5:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Paul, Rob, Billal Begueradj
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Paul, Rob, Billal Begueradj, lucascaro, Devon_C_Miller Nov 12 '18 at 5:18


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Paul, Rob, Billal Begueradj
If this question can be reworded to fit the rules in the help center, please edit the question.







  • 5





    Possible duplicate of Remove excess whitespace from within a string

    – Stephen Lake
    Nov 11 '18 at 14:27












  • 5





    Possible duplicate of Remove excess whitespace from within a string

    – Stephen Lake
    Nov 11 '18 at 14:27







5




5





Possible duplicate of Remove excess whitespace from within a string

– Stephen Lake
Nov 11 '18 at 14:27





Possible duplicate of Remove excess whitespace from within a string

– Stephen Lake
Nov 11 '18 at 14:27












2 Answers
2






active

oldest

votes


















1














$cleanString = preg_replace('/s+/', ' ', $yourString);





share|improve this answer






























    0














    Please have a look at the code below:



    <?php
    //the data seems to be actually an array
    $array = ["rn rn 300518</departureDate>rnttttttttt rnttttttttt rn </availabilityDetails>rn rn HYD</cityAirport>rn </departureLocationInfo>rn rn DXB</cityAirport>rn </arrivalLocationInfo>rn </availabilityProductInfo>702</orderClassesByCabin></cabinOption>",44,"AUHOT3116"];

    //should yield
    $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116";

    $trim = ["t","r","n","</",">"," "]; //characters or substrings you want removed

    foreach($array as &$value)
    $value = str_replace($trim,"-",$value); //removing unwanted characters
    $value = preg_replace('/[- ]2,/','-',$value); //removing duplicates
    $value = trim($value,"- "); //removing trailing and ending unwanted characters


    $replaced_output = implode("-",$array); //converting the initial array to string

    echo "<pre>";
    var_dump($desired_output,$replaced_output);


    https://3v4l.org/3cdqO



    Note that the expected string and the processed string are not identical because there was an element called 'cabinOption' that doesn't fit the removing criteria, so it was left as it was.



    EDIT: To have the processed string identical with the desired string, just add whatever string you want removed in the $trim array.



    https://3v4l.org/uujfC



    This may not be the best way to do it, it's just a possible solution for this specific case. You should consider a more generic approach, regular expressions etc.






    share|improve this answer

























    • its working for me thank you so much.....

      – Niru
      Nov 12 '18 at 6:15

















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    $cleanString = preg_replace('/s+/', ' ', $yourString);





    share|improve this answer



























      1














      $cleanString = preg_replace('/s+/', ' ', $yourString);





      share|improve this answer

























        1












        1








        1







        $cleanString = preg_replace('/s+/', ' ', $yourString);





        share|improve this answer













        $cleanString = preg_replace('/s+/', ' ', $yourString);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 '18 at 14:24









        Stephen LakeStephen Lake

        1,08811223




        1,08811223























            0














            Please have a look at the code below:



            <?php
            //the data seems to be actually an array
            $array = ["rn rn 300518</departureDate>rnttttttttt rnttttttttt rn </availabilityDetails>rn rn HYD</cityAirport>rn </departureLocationInfo>rn rn DXB</cityAirport>rn </arrivalLocationInfo>rn </availabilityProductInfo>702</orderClassesByCabin></cabinOption>",44,"AUHOT3116"];

            //should yield
            $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116";

            $trim = ["t","r","n","</",">"," "]; //characters or substrings you want removed

            foreach($array as &$value)
            $value = str_replace($trim,"-",$value); //removing unwanted characters
            $value = preg_replace('/[- ]2,/','-',$value); //removing duplicates
            $value = trim($value,"- "); //removing trailing and ending unwanted characters


            $replaced_output = implode("-",$array); //converting the initial array to string

            echo "<pre>";
            var_dump($desired_output,$replaced_output);


            https://3v4l.org/3cdqO



            Note that the expected string and the processed string are not identical because there was an element called 'cabinOption' that doesn't fit the removing criteria, so it was left as it was.



            EDIT: To have the processed string identical with the desired string, just add whatever string you want removed in the $trim array.



            https://3v4l.org/uujfC



            This may not be the best way to do it, it's just a possible solution for this specific case. You should consider a more generic approach, regular expressions etc.






            share|improve this answer

























            • its working for me thank you so much.....

              – Niru
              Nov 12 '18 at 6:15















            0














            Please have a look at the code below:



            <?php
            //the data seems to be actually an array
            $array = ["rn rn 300518</departureDate>rnttttttttt rnttttttttt rn </availabilityDetails>rn rn HYD</cityAirport>rn </departureLocationInfo>rn rn DXB</cityAirport>rn </arrivalLocationInfo>rn </availabilityProductInfo>702</orderClassesByCabin></cabinOption>",44,"AUHOT3116"];

            //should yield
            $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116";

            $trim = ["t","r","n","</",">"," "]; //characters or substrings you want removed

            foreach($array as &$value)
            $value = str_replace($trim,"-",$value); //removing unwanted characters
            $value = preg_replace('/[- ]2,/','-',$value); //removing duplicates
            $value = trim($value,"- "); //removing trailing and ending unwanted characters


            $replaced_output = implode("-",$array); //converting the initial array to string

            echo "<pre>";
            var_dump($desired_output,$replaced_output);


            https://3v4l.org/3cdqO



            Note that the expected string and the processed string are not identical because there was an element called 'cabinOption' that doesn't fit the removing criteria, so it was left as it was.



            EDIT: To have the processed string identical with the desired string, just add whatever string you want removed in the $trim array.



            https://3v4l.org/uujfC



            This may not be the best way to do it, it's just a possible solution for this specific case. You should consider a more generic approach, regular expressions etc.






            share|improve this answer

























            • its working for me thank you so much.....

              – Niru
              Nov 12 '18 at 6:15













            0












            0








            0







            Please have a look at the code below:



            <?php
            //the data seems to be actually an array
            $array = ["rn rn 300518</departureDate>rnttttttttt rnttttttttt rn </availabilityDetails>rn rn HYD</cityAirport>rn </departureLocationInfo>rn rn DXB</cityAirport>rn </arrivalLocationInfo>rn </availabilityProductInfo>702</orderClassesByCabin></cabinOption>",44,"AUHOT3116"];

            //should yield
            $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116";

            $trim = ["t","r","n","</",">"," "]; //characters or substrings you want removed

            foreach($array as &$value)
            $value = str_replace($trim,"-",$value); //removing unwanted characters
            $value = preg_replace('/[- ]2,/','-',$value); //removing duplicates
            $value = trim($value,"- "); //removing trailing and ending unwanted characters


            $replaced_output = implode("-",$array); //converting the initial array to string

            echo "<pre>";
            var_dump($desired_output,$replaced_output);


            https://3v4l.org/3cdqO



            Note that the expected string and the processed string are not identical because there was an element called 'cabinOption' that doesn't fit the removing criteria, so it was left as it was.



            EDIT: To have the processed string identical with the desired string, just add whatever string you want removed in the $trim array.



            https://3v4l.org/uujfC



            This may not be the best way to do it, it's just a possible solution for this specific case. You should consider a more generic approach, regular expressions etc.






            share|improve this answer















            Please have a look at the code below:



            <?php
            //the data seems to be actually an array
            $array = ["rn rn 300518</departureDate>rnttttttttt rnttttttttt rn </availabilityDetails>rn rn HYD</cityAirport>rn </departureLocationInfo>rn rn DXB</cityAirport>rn </arrivalLocationInfo>rn </availabilityProductInfo>702</orderClassesByCabin></cabinOption>",44,"AUHOT3116"];

            //should yield
            $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116";

            $trim = ["t","r","n","</",">"," "]; //characters or substrings you want removed

            foreach($array as &$value)
            $value = str_replace($trim,"-",$value); //removing unwanted characters
            $value = preg_replace('/[- ]2,/','-',$value); //removing duplicates
            $value = trim($value,"- "); //removing trailing and ending unwanted characters


            $replaced_output = implode("-",$array); //converting the initial array to string

            echo "<pre>";
            var_dump($desired_output,$replaced_output);


            https://3v4l.org/3cdqO



            Note that the expected string and the processed string are not identical because there was an element called 'cabinOption' that doesn't fit the removing criteria, so it was left as it was.



            EDIT: To have the processed string identical with the desired string, just add whatever string you want removed in the $trim array.



            https://3v4l.org/uujfC



            This may not be the best way to do it, it's just a possible solution for this specific case. You should consider a more generic approach, regular expressions etc.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 '18 at 14:53

























            answered Nov 11 '18 at 14:34









            Dan D.Dan D.

            580213




            580213












            • its working for me thank you so much.....

              – Niru
              Nov 12 '18 at 6:15

















            • its working for me thank you so much.....

              – Niru
              Nov 12 '18 at 6:15
















            its working for me thank you so much.....

            – Niru
            Nov 12 '18 at 6:15





            its working for me thank you so much.....

            – Niru
            Nov 12 '18 at 6:15



            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)