How do you execute a PHP script from the command line?

php.exe yourscript.php

Make sure your path includes the php bin folder.

Via windows?? or Linux??

He (she) said command line so I would assume he's talking about Windows...

@NardCake, but of course Linux too has commandline. Unless my brain is playing tricks on me!!

For Windows:
Open Cmd
set a path using:-
set PATH = %PATH%;c:\xampp\php //temporary setting a path
OR
Control Panel > System > Advanced System Settings > Environment Variables > look for and highlight the Path variable and click Edit.Append the PHP folder path //permanent setting a path

After setting a path run your code using:-
script-folder> php your-script-name.php

but of course Linux too has commandline. Unless my brain is playing tricks on me!!

When mentioning linux, he would probably have named it "shell" instead.

Aaahh, ok .... point noted.

Or "Terminal" :)

Yes the phrase command line is most often associated with the Windows CMD.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.