I come from Java/Netbeans, and I can indent my Java code using alt+shift+f, I have searched through this site and other articles, but I didn't find a good way to indent PHP.
What I found:
using pear PHP_beautifier
but I have to output the result to a different file or simply copy on terminal result.
using PHP beautifier on the web
I have tried using M-x indent-region in PHP-mode but nothing changes. I tried in jdee for Java code M-x indent-region also doesn't work.
I found other solutions but for JSON, com.lang, Asytle (C/C++/C#)
this is my .emacs
https://gist.github.com/azzamsa/1f76b8ca00fd2737ae08a5c3f6dc6b3f
I am using :
php-mode-1.18.2(ejmr/php-mode), GNU Emacs 24.4.1
and installed php-mode from elpa repo.
After following phils suggestion to use Tab, it works. But when I try to break the code format, and try to see the result using C-x+ h and Tab, it doesn't indent the code properly as what online formater does. e.g.:
public function
__construct($name) {
$this->name = $name;
//$this->numLeg = $numLeg;
}
public
function
bark() {
return "Woof!";
}
public
function
greet() {
return "hello i am " . "$this->name";
}
}
There is no result even when I use indent-region. I also tried to use fill-region, and other choice of fill, but no luck. But the online formatter can handle this nicely, the result from online formatter and the expected one is:
class Dog {
public $numLegs = 4;
public $name;
public function __construct($name) {
$this->name = $name;
//$this->numLeg = $numLeg;
}
public function bark() {
return "Woof!";
}
public function greet() {
return "hello i am " . "$this->name";
}
}
$dog1 = new Dog("Barker");
$dog2 = new DOg("Amigo");

indent-region(usually invoked viaTAB) is the correct answer, so you should show an example of what isn't working for you (with the original formatting, and the formatting you are expecting to see after reindenting).indent-regiondeals only with indentation, not joining statements which are (bizarrely) split over multiple lines into single lines. It doesn't reformat your code; it just sets the indent of each line. In other words, what you're asking for isn't "how to indent PHP code". I don't thinkphp-modecan help you, so you might as well continue to use the other tools you've found.php-beautifier.elthough.