php - How can i implement escapeshellarg inside a URL?

Solution:
What's happening is that you are currently trying to run a function inside of a string. This is possible with extra steps, but is not desirable.
What you want to do is concatenate the string with the output of the function. You can inline that in this manner:
exec('cat /opt/application/userdata/' . escapeshellarg($username) . '/following | grep -w ' . escapeshellarg($name))
(noticed I used single quotes ['
], as no expansion is happening within the string, this is somewhat faster and keeps it separate)
Or you can perform the operation earlier, and simply include ("expand") the variables in the string, like your first example hints at:
$username = escapeshellarg($username);
$name = escapeshellarg($name);
exec("cat /opt/application/userdata/$username/following | grep -w $name")
(noticed I used double quotes ["
] as there is expansion happening within the string)
Answer
Solution:
Theescapeshellarg()
function is a PHP built-in, but you're attempting to execute it as a shell function. You can fix it by simply pulling the function out of the string scope and concatenating the results:
exec("cat /opt/application/userdata/" . escapeshellarg($username) . "/following | grep -w " . escapeshellarg($name));
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non-numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.