Last active
September 29, 2017 17:19
-
-
Save danielpataki/4075ec96709c39b2e404 to your computer and use it in GitHub Desktop.
Beginner PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if it is before 10am { | |
<h1>Good Morning</h1> | |
} | |
if it is after 6pm { | |
<h1>Good Evening</h1> | |
} | |
otherwise { | |
<h1>Good Day</h1> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function get_excerpt( $text, $length = 200, $append = '...' ) { | |
if( strlen( $text ) < $length ) { | |
return $text; | |
} | |
else { | |
$excerpt = substr( $text, 0, $length ); | |
$excerpt .= $append; | |
return $excerpt; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$details = array( "name" => "Daniel Pataki", "Age" => "30", "Twitter" => "http://twitter.com/danielpataki" ); | |
echo "<ul>"; | |
foreach( $details as $label => $value ) { | |
echo "<li><strong>" . $label . "</strong>: " . $value . "</li>"; | |
} | |
echo "</ul>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$names = array( "Daniel Pataki", "Raelene Morey", "James Farmer" ); | |
echo "<ul>"; | |
foreach( $names as $name ) { | |
echo "<li>" . $name . "</li>"; | |
} | |
echo "</ul>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$unit = "C"; | |
$temp = 29; | |
if( $unit == 'F' ) { | |
$temp = $temp * 9 / 5 + 32; | |
} | |
$forecast = "The weather today will be great, a Sunny " . $temp . $unit; | |
echo $forecast; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function make_excerpt( $text, $length = 200, $append = '...' ) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function display_post( $postdata ) { | |
echo "<div class='post'>"; | |
echo "<h1>" . $postdata['post_title'] . "</h1>"; | |
echo "<p>" . $postdata['post_excerpt'] . "</p>"; | |
echo "<div class='post-meta'>Published on " . $postdata['post_date'] . " by " . $postdata['post_author'] . "</div>"; | |
echo "</div>"; | |
} | |
$posts = array( | |
0 => array( | |
"post_title" => "My First Post", | |
"post_excerpt" => "This is a short snippet of text from the first post", | |
"post_date" => "2015 December 1", | |
"post_author" => "Daniel Pataki" | |
), | |
1 => array( | |
"post_title" => "Second Post", | |
"post_excerpt" => "Short exceprt for post number 2", | |
"post_date" => "2015 December 4", | |
"post_author" => "Raelene Morey" | |
) | |
); | |
foreach( $posts as $post ) { | |
display_post( $post ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello HTML | |
<?php echo "Hello PHP"; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple if Statement | |
if( $speed > 50 ) { | |
echo "You are over the speed limit"; | |
} | |
// If and else statement | |
if( $age < 21 ) { | |
echo "You may not buy alcohol"; | |
} | |
else { | |
echo "You may buy alcohol"; | |
} | |
// If, else if and else statement | |
if( $speed < 25 ) { | |
echo "You are too slow"; | |
} | |
elseif( $speed > 120 ) { | |
echo "You are too fast"; | |
} | |
else { | |
echo "Your speed is just right!"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -L -o 'install.sh' http://bit.ly/1hBfq57 && curl -L -o 'Vagrantfile' http://bit.ly/1mE3Qt9 && vagrant up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$posts = array( | |
0 => array( | |
"post_title" => "My First Post", | |
"post_excerpt" => "This is a short snippet of text from the first post", | |
"post_date" => "2015 December 1", | |
"post_author" => "Daniel Pataki" | |
), | |
1 => array( | |
"post_title" => "Second Post", | |
"post_excerpt" => "Short exceprt for post number 2", | |
"post_date" => "2015 December 4", | |
"post_author" => "Raelene Morey" | |
) | |
); | |
foreach( $posts as $post ) { | |
echo "<div class='post'>"; | |
echo "<h1>" . $post['post_title'] . "</h1>"; | |
echo "<p>" . $post['post_excerpt'] . "</p>"; | |
echo "<div class='post-meta'>Published on " . $post['post_date'] . " by " . $post['post_author'] . "</div>"; | |
echo "</div>"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = 'Daniel'; | |
$age = 30; | |
$interests = array( 'guitar', 'singing', 'squash', 'running', 'board games' ); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$name = "Daniel"; | |
echo $name; | |
?> |
In the wpmudev intro to WP course, you meant to include excerpt.php but instead, it shows variable.php, so we can't see the proper code and it doesn't make sense.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice