-1
<html>
    <input type='text' name='mobile phone' value='
        <?php if (strpos($phone_number, '07') === 0) {
            echo $phone_number;
        } else {
            echo $alt_phone;
        }?>'
</html>

Works fine. I would like to combine the above with:

    <?php if (!empty($alt_phone)) {
        echo $alt_phone;
    } else {
        echo '07777777777';
    }?>'`

I have tried ELSEIF with the new condition, and a completely separate <?php ?> section and both times I get a blank page, instead of a textbox with a telephone number in it.

I am trying to achieve this: If $phone_number is a mobile, enter this number, otherwise enter the alt_phone, unless $alt_phone is blank, then enter '07777777777'.

jww
  • 97,681
  • 90
  • 411
  • 885
Alex Nicol
  • 17
  • 3
  • 1
    Please show the attempt using `elseif`. It should work when you use it like this `if (strpost(...) === 0) { } elseif (!empty($alt_phone)) { } else { }` – kero Apr 10 '15 at 15:18
  • "and both times I get a blank page" - have you tried [turning on error reporting](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851)? – IMSoP Apr 10 '15 at 15:40

2 Answers2

0

try

<?php 
if (!empty($phone_number)) {
echo $phone_number;
}
elseif(!empty($alt_phone)) 
{
echo $alt_phone;
}
else{
echo '07777777777';
 }
?>'`
Maninderpreet Singh
  • 2,569
  • 2
  • 17
  • 31
0

This will do the trick

<?php 

if (strpos($phone_number, '07') === 0) {
    echo $phone_number;
} 
else if (!empty($alt_phone)) {
    echo $alt_phone;
} 
else {
   echo '07777777777';
}
?>
Med
  • 2,035
  • 20
  • 31