Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding text if it does not exist

Status
Not open for further replies.

natefanaro

Technical User
Jun 10, 2002
17
US
I am looking for something that will add http:// if it does not exist in a form. If it does exist, don't add http://

so would be changed to
would not be changed at all.

I think that I would have to use regular expressions, or preg_replace. Any ideas?
 
ok, it didn't work origionally but I played around enough to get it going. I think you added a period here: $text=" . $text; by mistake. Thank you very much for your help. here's a page that i whipped up. You can try it out if you would like.

<?
if ($submit){
if(!preg_match(&quot;/http:\/\//i&quot;,$text)) {
echo &quot;} else {
echo &quot;$text&quot;;
}
} {
?>
<form action=&quot;testhttp.php&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;text&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;>
</form>
<?
}
?>
 
Nope, that was what I meant to type, but Tek Tips messed it up after I submitted it. It added a &quot;;&quot;--Probably because I had TGML on. This was what I meant:

<?
if(!preg_match(&quot;/http:\/\//i&quot;,$text)) {
$text=&quot; . $text;//no semicolon untill the end.
}
?>

Rick -----------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top