PHP: trim() doesn't work with two variables












-1















Alright, guys, so it is either there is some minor issue I don't catch or it's just time to sleep. Whatever it is, I would highly appreciate your advice.



I am generating an XML file with PHP. Everything worked smoothly till the moment I input this line:



$out .= "<name>" . trim($prod["name"], $prod["model"]) . "</name>";


and so an error occurred (logs below).



Everything works nicely if one of the variables is changed into the pure string. Say, both of these work perfectly:



$out .= "<name>" . trim($prod["name"], "123") . "</name>";
$out .= "<name>" . trim("123", $prod["model"]) . "</name>";


Here is what logs say:



mod_fcgid: stderr: PHP Warning:  SimpleXMLElement::__construct(): Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !

mod_fcgid: stderr: Bytes: 0x9A 0xD0 0xB5 0xD0 in /xml/file.phpon line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): picture&gt;&lt;vendor&gt;VES electric&lt;/vendor&gt;&lt;stock_quantity&gt;1000&lt;/stock_quantity&gt;&lt;name&gt; in /xml/file.php on line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): ^ in /xml/file.php on line 193

mod_fcgid: stderr: PHP Fatal error: Uncaught Exception: String could not be parsed as XML in /xml/file.php:193

mod_fcgid: stderr: Stack trace:

mod_fcgid: stderr: #0 /xml/rozetka.php(193): SimpleXMLElement->__construct('<?xml version="...')

mod_fcgid: stderr: #1 {main}

mod_fcgid: stderr: thrown in /xml/file.php on line 193


Thanks again for your help.










share|improve this question























  • As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

    – Magnus Eriksson
    Nov 28 '18 at 23:26













  • are you sure that you understand what 2nd argument to trim does?

    – Iłya Bursov
    Nov 28 '18 at 23:26











  • @MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

    – Iłya Bursov
    Nov 28 '18 at 23:28











  • @IłyaBursov - I know. I'm asking the OP if that's the intention.

    – Magnus Eriksson
    Nov 28 '18 at 23:28








  • 1





    @VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

    – Iłya Bursov
    Nov 28 '18 at 23:37


















-1















Alright, guys, so it is either there is some minor issue I don't catch or it's just time to sleep. Whatever it is, I would highly appreciate your advice.



I am generating an XML file with PHP. Everything worked smoothly till the moment I input this line:



$out .= "<name>" . trim($prod["name"], $prod["model"]) . "</name>";


and so an error occurred (logs below).



Everything works nicely if one of the variables is changed into the pure string. Say, both of these work perfectly:



$out .= "<name>" . trim($prod["name"], "123") . "</name>";
$out .= "<name>" . trim("123", $prod["model"]) . "</name>";


Here is what logs say:



mod_fcgid: stderr: PHP Warning:  SimpleXMLElement::__construct(): Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !

mod_fcgid: stderr: Bytes: 0x9A 0xD0 0xB5 0xD0 in /xml/file.phpon line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): picture&gt;&lt;vendor&gt;VES electric&lt;/vendor&gt;&lt;stock_quantity&gt;1000&lt;/stock_quantity&gt;&lt;name&gt; in /xml/file.php on line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): ^ in /xml/file.php on line 193

mod_fcgid: stderr: PHP Fatal error: Uncaught Exception: String could not be parsed as XML in /xml/file.php:193

mod_fcgid: stderr: Stack trace:

mod_fcgid: stderr: #0 /xml/rozetka.php(193): SimpleXMLElement->__construct('<?xml version="...')

mod_fcgid: stderr: #1 {main}

mod_fcgid: stderr: thrown in /xml/file.php on line 193


Thanks again for your help.










share|improve this question























  • As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

    – Magnus Eriksson
    Nov 28 '18 at 23:26













  • are you sure that you understand what 2nd argument to trim does?

    – Iłya Bursov
    Nov 28 '18 at 23:26











  • @MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

    – Iłya Bursov
    Nov 28 '18 at 23:28











  • @IłyaBursov - I know. I'm asking the OP if that's the intention.

    – Magnus Eriksson
    Nov 28 '18 at 23:28








  • 1





    @VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

    – Iłya Bursov
    Nov 28 '18 at 23:37
















-1












-1








-1








Alright, guys, so it is either there is some minor issue I don't catch or it's just time to sleep. Whatever it is, I would highly appreciate your advice.



I am generating an XML file with PHP. Everything worked smoothly till the moment I input this line:



$out .= "<name>" . trim($prod["name"], $prod["model"]) . "</name>";


and so an error occurred (logs below).



Everything works nicely if one of the variables is changed into the pure string. Say, both of these work perfectly:



$out .= "<name>" . trim($prod["name"], "123") . "</name>";
$out .= "<name>" . trim("123", $prod["model"]) . "</name>";


Here is what logs say:



mod_fcgid: stderr: PHP Warning:  SimpleXMLElement::__construct(): Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !

mod_fcgid: stderr: Bytes: 0x9A 0xD0 0xB5 0xD0 in /xml/file.phpon line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): picture&gt;&lt;vendor&gt;VES electric&lt;/vendor&gt;&lt;stock_quantity&gt;1000&lt;/stock_quantity&gt;&lt;name&gt; in /xml/file.php on line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): ^ in /xml/file.php on line 193

mod_fcgid: stderr: PHP Fatal error: Uncaught Exception: String could not be parsed as XML in /xml/file.php:193

mod_fcgid: stderr: Stack trace:

mod_fcgid: stderr: #0 /xml/rozetka.php(193): SimpleXMLElement->__construct('<?xml version="...')

mod_fcgid: stderr: #1 {main}

mod_fcgid: stderr: thrown in /xml/file.php on line 193


Thanks again for your help.










share|improve this question














Alright, guys, so it is either there is some minor issue I don't catch or it's just time to sleep. Whatever it is, I would highly appreciate your advice.



I am generating an XML file with PHP. Everything worked smoothly till the moment I input this line:



$out .= "<name>" . trim($prod["name"], $prod["model"]) . "</name>";


and so an error occurred (logs below).



Everything works nicely if one of the variables is changed into the pure string. Say, both of these work perfectly:



$out .= "<name>" . trim($prod["name"], "123") . "</name>";
$out .= "<name>" . trim("123", $prod["model"]) . "</name>";


Here is what logs say:



mod_fcgid: stderr: PHP Warning:  SimpleXMLElement::__construct(): Entity: line 1: parser error : Input is not proper UTF-8, indicate encoding !

mod_fcgid: stderr: Bytes: 0x9A 0xD0 0xB5 0xD0 in /xml/file.phpon line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): picture&gt;&lt;vendor&gt;VES electric&lt;/vendor&gt;&lt;stock_quantity&gt;1000&lt;/stock_quantity&gt;&lt;name&gt; in /xml/file.php on line 193

mod_fcgid: stderr: PHP Warning: SimpleXMLElement::__construct(): ^ in /xml/file.php on line 193

mod_fcgid: stderr: PHP Fatal error: Uncaught Exception: String could not be parsed as XML in /xml/file.php:193

mod_fcgid: stderr: Stack trace:

mod_fcgid: stderr: #0 /xml/rozetka.php(193): SimpleXMLElement->__construct('<?xml version="...')

mod_fcgid: stderr: #1 {main}

mod_fcgid: stderr: thrown in /xml/file.php on line 193


Thanks again for your help.







php error-handling trim






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 23:22









Vlad B.Vlad B.

147




147













  • As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

    – Magnus Eriksson
    Nov 28 '18 at 23:26













  • are you sure that you understand what 2nd argument to trim does?

    – Iłya Bursov
    Nov 28 '18 at 23:26











  • @MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

    – Iłya Bursov
    Nov 28 '18 at 23:28











  • @IłyaBursov - I know. I'm asking the OP if that's the intention.

    – Magnus Eriksson
    Nov 28 '18 at 23:28








  • 1





    @VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

    – Iłya Bursov
    Nov 28 '18 at 23:37





















  • As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

    – Magnus Eriksson
    Nov 28 '18 at 23:26













  • are you sure that you understand what 2nd argument to trim does?

    – Iłya Bursov
    Nov 28 '18 at 23:26











  • @MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

    – Iłya Bursov
    Nov 28 '18 at 23:28











  • @IłyaBursov - I know. I'm asking the OP if that's the intention.

    – Magnus Eriksson
    Nov 28 '18 at 23:28








  • 1





    @VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

    – Iłya Bursov
    Nov 28 '18 at 23:37



















As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

– Magnus Eriksson
Nov 28 '18 at 23:26







As far as I can see, the trim()-function isn't throwing any errors? Check what $out actually contains after using the trim. Just to make sure, you're trying to trim away the chars in $prod['model'] from $prod['name']? Since the second argument is what you actually should trim away.

– Magnus Eriksson
Nov 28 '18 at 23:26















are you sure that you understand what 2nd argument to trim does?

– Iłya Bursov
Nov 28 '18 at 23:26





are you sure that you understand what 2nd argument to trim does?

– Iłya Bursov
Nov 28 '18 at 23:26













@MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

– Iłya Bursov
Nov 28 '18 at 23:28





@MagnusEriksson 2nd argument is char mask, so all symbols which appear in model, will be trimmed from name

– Iłya Bursov
Nov 28 '18 at 23:28













@IłyaBursov - I know. I'm asking the OP if that's the intention.

– Magnus Eriksson
Nov 28 '18 at 23:28







@IłyaBursov - I know. I'm asking the OP if that's the intention.

– Magnus Eriksson
Nov 28 '18 at 23:28






1




1





@VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

– Iłya Bursov
Nov 28 '18 at 23:37







@VladB. then you should not use trim, but str_replace, because trim('product pabc1', 'pabc1') will return roduct

– Iłya Bursov
Nov 28 '18 at 23:37














1 Answer
1






active

oldest

votes


















0














As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!






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%2f53529599%2fphp-trim-doesnt-work-with-two-variables%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
    Thanks for your help, guys!






    share|improve this answer




























      0














      As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
      Thanks for your help, guys!






      share|improve this answer


























        0












        0








        0







        As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
        Thanks for your help, guys!






        share|improve this answer













        As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
        Thanks for your help, guys!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 23:45









        Vlad B.Vlad B.

        147




        147
































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53529599%2fphp-trim-doesnt-work-with-two-variables%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)