renathy Posted November 8, 2011 Report Share Posted November 8, 2011 Vai var uzrakstīt regexpu, ja links var būt interna vai external? R. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 8, 2011 Report Share Posted November 8, 2011 Nūūū.... http://letmegooglethat.com/?q=check+that+link+is+external+regex+stackoverflow Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 8, 2011 Report Share Posted November 8, 2011 var rx = new RegExp(location.host); console.log(rx); /stackoverflow.com/ console.log(rx.test('http://dagrevis.lv/')); false console.log(rx.test('http://stackoverflow.com/questions/2910946/test-if-links-are-external-with-jquery-javascript')); true ...tas būtu ar JavaScript. Quote Link to comment Share on other sites More sharing options...
renathy Posted November 8, 2011 Author Report Share Posted November 8, 2011 Es varbūt kko nepareizi saprotu, bet man vajaga: PHP regexpu, ko liek preg_match un viņš validē - vienalga vai tas ir external, vai internal urlis. Ja tas nav ne extenral, ne internal, tad nevaldiē. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 8, 2011 Report Share Posted November 8, 2011 Pirmkārt, nav tāds jēdziens kā PHP regexs. Regexs ir regexs. Otrkārt, tev vajag regexu, kurš atgriež `true`, ja tas ir links (vienalga - 'external' vai 'internal'), bet `false`, ja tas nav links? Quote Link to comment Share on other sites More sharing options...
renathy Posted November 8, 2011 Author Report Share Posted November 8, 2011 Jā. Tieši tā man vajaga... Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 8, 2011 Report Share Posted November 8, 2011 filter_var() + FILTER_VALIDATE_URL. Quote Link to comment Share on other sites More sharing options...
marcis Posted November 8, 2011 Report Share Posted November 8, 2011 Kopš kura laika HTML jāpārsē ar regex? Lūk piemērs, kur es absolūtiem urļiem (kas nav mailto: linki) piemetu atribūtu rel="nofollow" http://pastie.org/2830781 Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 8, 2011 Report Share Posted November 8, 2011 Smagi, Mārci. P.S. http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 :D :D Quote Link to comment Share on other sites More sharing options...
Mr.Key Posted November 9, 2011 Report Share Posted November 9, 2011 ņemot vērā TLD, kas pieļauj domenu "kautkas", principā jāčeko pēc protokola prefiksa: strpos('://') (vai 'http://') - ja ir, būs ārējais, pārējais būs iekšējais. ja neņem vērā TLD, var mēģināt parsēt arī pēc tā, vai sākas ar kaut ko domeinam līdzīgu. Nu labi, varu iekopēt reiz taisīto risinājumu. if (preg_match("/^([a-z]+:\/\/)/", $url)) { // ārējais } else { // iekšējais } Quote Link to comment Share on other sites More sharing options...
marrtins Posted November 9, 2011 Report Share Posted November 9, 2011 http://lv.php.net/parse_url 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.