gkazhus Posted June 7, 2010 Report Share Posted June 7, 2010 Kā pareizi uzrakstīt if else nosacījumu ka vispirms tiek pārbaudīts vai laukā ir ierakstīts http:// , ja nav tad tiek pielikts šobrīd man ir tikai otrā daļa gatava ka tiek uzreiz pielikts http:// $link_URL = "http://" . $_POST["fname"]; Quote Link to comment Share on other sites More sharing options...
sandis_m Posted June 7, 2010 Report Share Posted June 7, 2010 Šito gadījumā nevajadzētu ar reg expr Quote Link to comment Share on other sites More sharing options...
gkazhus Posted June 7, 2010 Author Report Share Posted June 7, 2010 Šito gadījumā nevajadzētu ar reg expr Un kā viņu pareizi uzrakstīt? Quote Link to comment Share on other sites More sharing options...
m8t Posted June 7, 2010 Report Share Posted June 7, 2010 (edited) Apmēram šādi $regExpr = "http://"; $look = preg_match("/".$regExpr."/", $_POST["fname"]); if($look == false) { $link_URL = "http://" . $_POST["fname"]; } else { $link_URL = $_POST["fname"]; } echo $link_URL; Edited June 7, 2010 by m8t Quote Link to comment Share on other sites More sharing options...
esir Posted June 7, 2010 Report Share Posted June 7, 2010 if(substr($_POST['fname'], 0, 7) == 'http://') :P Quote Link to comment Share on other sites More sharing options...
gkazhus Posted June 7, 2010 Author Report Share Posted June 7, 2010 Apmēram šādi $regExpr = "http://"; $look = preg_match("/".$regExpr."/", $_POST["fname"]); if($look == false) { $link_URL = "http://" . $_POST["fname"]; } else { $link_URL = $_POST["fname"]; } echo $link_URL; Lielais paldies nostraadaaja! Tik pareizais kods būtu šāds: $regExpr = "http://";'>http://"; $look = preg_match("/".$regExpr."/", $_POST["fname"]); if($look == false) { $link_URL = $_POST["fname"]; } else { $link_URL = "http://" . $_POST["fname"]; } Quote Link to comment Share on other sites More sharing options...
emsy Posted June 7, 2010 Report Share Posted June 7, 2010 Kāde jēga likt "$look==false", ja ifiem gadījumā ja mainīgā vērtība ir boo, tad pie false neizpildās un pie true izpildās, vieglāk nebūtu: if(!$look) { $link_URL = $_POST["fname"]; } else { $link_URL = "http://" . $_POST["fname"]; } Quote Link to comment Share on other sites More sharing options...
indoom Posted June 7, 2010 Report Share Posted June 7, 2010 ātrāk $link_URL = 'http://' . str_replace('http://','',$_POST['fname']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.