Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialwilliamrossi
6,232 PointsIf null don't print anything
Hi all, i'm doing a project using php for the first time and struggling with it.
certain things are returning "Null"
how can I work this into an if statement
<?=str_replace('height=', 'data-height=',$series['description'])?>
so if null, don't print anything.
1 Answer

Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointstry this
<?php
<?
if($series['description']!=""){
$new_string= str_replace('height=', 'data-height=',$series['description']);
echo $new_string;
}
?>
or
<?
if(isset($series['description'])){
$new_string= str_replace('height=', 'data-height=',$series['description']);
echo $new_string;
}
?>
so it wont print anything if $series['description'] is null
Gregg Mojica
11,506 PointsGregg Mojica
11,506 Pointsyou can check if it's null using is_null