Coding style
Moderator: General Moderators
Coding style
I would like to make my code a better look. I read some articles, but didn't find all information. Please could recommend some sites where I can find how to style php and html and mysql inside php script in a proper way.
Last edited by meee on Sun Mar 06, 2011 8:05 am, edited 1 time in total.
Re: Coding style
Read Clean Code by Robert Martin. Yes, the entire book.
And then we can talk about good looking code.
And then we can talk about good looking code.
Re: Coding style
Check out the coding conventions on the PEAR website. They are considered the standards for PHP
http://pear.php.net/manual/en/standards.php
http://pear.php.net/manual/en/standards.php
Re: Coding style
thank you, I found a lot of answers in the mentioned site.
I have just two more questions:
How do you implement php inside html block.
like this:
or like this:
or other way?
I have just two more questions:
How do you implement php inside html block.
like this:
Code: Select all
...
<div>
<div>
<p>
<?php
if ($example==TRUE){
echo "statement";
}
?>
</p>
</div>
</div>
...
Code: Select all
...
<div>
<div>
<p>
<?php
if ($example==TRUE){
echo "statement";
}
?>
</p>
</div>
</div>
...
Re: Coding style
I prefer to keep the indentation of the markup (HTML), it looks more organized that way (to me).
Re: Coding style
I need just one more answer to style my code in a proper way
. Is the following a common way or should I do different? I am confusing if it is ok to have so many opening and closing php tags inside the code, and this is just a tiny sniped of the code.
Code: Select all
<div>
<!--some html code here !-->
<li>title 1</li>
<li>title 2</li>
<li>
<?php if($userId){
?>
<a href="/exmployments.php"><a href="/exmployments.php"><?php=$LANG['employments']?></a></a>
<?php
}else{
?>
<a href="/login.php"><?php=$LANG['employments']?></a>
<?php
}
?>
</li>
</ul>
</div> - AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Coding style
It is OK, but it might look a little better if you consider this: http://php.net/manual/en/control-struct ... syntax.php Some people like it, some don't.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.