I am new with php so this might be a silly question. I have this code.. $message = str_replace( array( '%TITLE%', '%VOUCHER%', '%BUYERUSER%', '%DEALPRICE%', '%DIFFERENCE%', '%DATEOFPURCH%' ), array( $offer->post_title, $voucher_code, $user->user_nicename, $offer->deal_owner_price, $offer->deal_sale_price - $offer->deal_owner_price, date("d/m/y") ), $message ); Code (markup): now I would like to set the value of '%DIFFERENCE%' to a string saying not available or something, if $offer->deal_sale_price field is left empty. Any help please? Thanks.
Easiest way would be to check the value before using it. Something like this (before the str_replace, just swap the $offer->deal_sale_price with $offer_price in the array) : $offer_price = (empty($offer->deal_sale_price) ? 'not available' : $offer->deal_sale_price);
Really sorry but I didnt quite get how the end code should be. I am completely new in php so please bear with me
$offer_price = (empty($offer->deal_sale_price) ? 'not available' : $offer->deal_sale_price - $offer->deal_owner_price); $message = str_replace( array( '%TITLE%', '%VOUCHER%', '%BUYERUSER%', '%DEALPRICE%', '%DIFFERENCE%', '%DATEOFPURCH%' ), array( $offer->post_title, $voucher_code, $user->user_nicename, $offer->deal_owner_price, $offer_price, date("d/m/y") ), $message ); PHP: That should do it.