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">
3
  • Can you show your <form> code so we can see the name of the <input> Commented Mar 30, 2014 at 4:22
  • better possible duplicate of stackoverflow.com/questions/6111934/… or stackoverflow.com/questions/6240414/… Commented Mar 30, 2014 at 4:25
  • <input type="text" name="sitehost" value="<?=$sitehost;?>"> <input type="submit" value="submit"></p> Commented Mar 30, 2014 at 4:38

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Thank u very much,I fixed the Issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.