PHP: trim() doesn't work with two variables
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><vendor>VES electric</vendor><stock_quantity>1000</stock_quantity><name> 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
|
show 5 more comments
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><vendor>VES electric</vendor><stock_quantity>1000</stock_quantity><name> 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
As far as I can see, thetrim()
-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, becausetrim('product pabc1', 'pabc1')
will returnroduct
– Iłya Bursov
Nov 28 '18 at 23:37
|
show 5 more comments
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><vendor>VES electric</vendor><stock_quantity>1000</stock_quantity><name> 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
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><vendor>VES electric</vendor><stock_quantity>1000</stock_quantity><name> 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
php error-handling trim
asked Nov 28 '18 at 23:22
Vlad B.Vlad B.
147
147
As far as I can see, thetrim()
-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, becausetrim('product pabc1', 'pabc1')
will returnroduct
– Iłya Bursov
Nov 28 '18 at 23:37
|
show 5 more comments
As far as I can see, thetrim()
-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, becausetrim('product pabc1', 'pabc1')
will returnroduct
– 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
|
show 5 more comments
1 Answer
1
active
oldest
votes
As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!
add a comment |
As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!
add a comment |
As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!
As @IłyaBursov and @MagnusEriksson pointed out, I had to use str_replace() instead of trim().
Thanks for your help, guys!
answered Nov 28 '18 at 23:45
Vlad B.Vlad B.
147
147
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 returnroduct
– Iłya Bursov
Nov 28 '18 at 23:37