Asked  1 Year ago    Answers:  5   Viewed   10 times

First off, I'm confused on how to run PHP in the command-line. I've been reading several articles on the web and they all say that you need a CLI (Command Line Interface).

Basically, I have PHP files, and I want to call something like this:

php -l somefile.php

But I'm wanting to check a string, not a file! How can this be done? Can using STDIN, STDOUT, or STDERR help with this at all?

If so, how? Can someone provide an example here?

Also, where do I place that above code? I don't have access to a command-line (I don't think), or do I just place it within a PHP file itself that will run? Will it execute this code, in that case, within the command-line?

I'm completely clueless on how this PHP command-line thing works... Can someone please help shed some light on this exactly?



If you want lint code (not within a file) the only option is to write a wrapper.

Assuming your $HOME/bin precedes /usr/bin, you could install your wrapper in $HOME/bin/php that has a different option for command-line linting. The wrapper would create a temporary file, put the code in there, run /usr/bin/php -l file and then delete the temporary file.


Saturday, May 29, 2021

Well, you can tell by looking at the format. When you serialize an array, you get a string that looks like a:1:{i:0;s:3:"foo"} And if you serialize an object, you get: o:7:"myclass":1:{s:3:"foo";s:3:"bar";}.

So if you want to test rudimentary, you can do these two regexes:




for arrays and objects respectively.

Note that this just checks for the generic form. To tell if it's a valid serialized string, you need to run it through unserialize() and test the return is_array($result) and is_object($result)...

Thursday, April 1, 2021

Looks like your problem is that you are trying to run python from within the Python interpreter, which is why you're seeing that traceback.

Make sure you're out of the interpreter, then run the python command from bash or command prompt or whatever.

Wednesday, June 2, 2021

You have problem with use of use:)

The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace declarations. This is because the importing is done at compile time and not runtime, so it cannot be block scoped.

Try this code:

use DompdfDompdf;

require_once '';

// instantiate and use the dompdf class
$dompdf = new DOMPDF();
$html = "

$dompdf->setPaper('A4', 'landscape');
$pdf = $dompdf->output();
file_put_contents("page.pdf", $pdf);

<a href="./page.pdf" download="page.pdf">Download the pdf</a>
Tuesday, August 31, 2021

Using a list comprehension along with split:

sample_list = ['', '',
    '', '', '',
result_list1 = [i.split('.')[0] for i in sample_list]

This prints:

['Ironman', 'Hulk', 'Thor', 'Antman', 'Loki', 'Captain']

This strategy is to retain, for each input domain, just the component up to, but not including, the first dot separator. For the second list, we can use re.sub here:

result_list2 = [re.sub(r'^[^.]+.', '', i) for i in sample_list]

This prints:

['', '', '', '',
 '', '']
Thursday, September 2, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :