0

How can I add a 'http://' component to a post variable so that it automatically adds that part so if someone submits: 'www.1webtutor.in' is will register as http://www.1webtutor.in.

Change non-http value in text field to http value when someone insert value as above.

in the form at "http://1webtutor.in/tools/test/"

<input type="text" name="sitehost">
Zeeshan
  • 1,659
  • 13
  • 17

2 Answers2

0

You want to use substr which for your future references can be used to start from the end if you start using negative values.

<input name="sitehost" type="text" value="<?php
if (substr($sitehost,0,7)!='http://') {echo 'http://';}
?>" />

The php.net/substr page has more information.

John
  • 1
  • 13
  • 98
  • 177
0

Try this....

    <?php
    $url    =   'www.1webtutor.in';
    if (strpos($url,'http://') === false){
        $url = 'http://'.$url;
    }
    echo $url;
    ?>
<input type="text" name="sitehost" value='<?php echo $url; ?>'>

Ref Click here

Zeeshan
  • 1,659
  • 13
  • 17