Rich Bitch Posted March 12, 2011 Report Share Posted March 12, 2011 (edited) Būtu nepieciešams izgūt teksta daļas no koda (telefona numurus), kas ar javascript tiek sadalīti. Kods: ... <script type="text/javascript">//<![CDATA[ var kods = "371"; var numurs = "76543210"; document.write(kods + ' ' + numurs) //]]></script> ... Varbūt kāds var palīdzēt ar ieteikumiem, kā šo telefona numuru ar valsts kodu varētu izgūt no koda un salikt kaut vai masīvā, lai tālāk tos apvienotu? Es iedomājos, ka to varētu ar preg_match, bet es nemāku pareizu "expression" uztaisīt. Edited March 12, 2011 by Rich Bitch Quote Link to comment Share on other sites More sharing options...
sandis_m Posted March 12, 2011 Report Share Posted March 12, 2011 emm.. a nebija gadījumā tā, ka tas preg_match nevar neko izdarīt ar javascript? Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 12, 2011 Report Share Posted March 12, 2011 http://www.regular-expressions.info/javascript.html Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted March 12, 2011 Author Report Share Posted March 12, 2011 Bet es pieņemsim to kodu saglabāju kā txt failu, tad jau var ņemt visu "contentu" kā string un ar preg_match analizēt datus. Vai tad nevar uztaisīt preg_match_all expression un dabūt tos datus ārā? Quote Link to comment Share on other sites More sharing options...
marcis Posted March 12, 2011 Report Share Posted March 12, 2011 /var\skods\s=\s"(\d+)";\svar\snumurs\s=\s"(\d+)";/U Quote Link to comment Share on other sites More sharing options...
wintermute Posted March 12, 2011 Report Share Posted March 12, 2011 Man gan ir smagas aizdomas, ka Rich Bitch meklē koda dizaina kļūdas nepilnīgā labojuma diezgan pastulbā patch'a ātru fix'u. Citiem vārdiem : operējam smadzenes caur dirsu. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 12, 2011 Report Share Posted March 12, 2011 @wintermute Ko, ko, ko?? Quote Link to comment Share on other sites More sharing options...
marcis Posted March 12, 2011 Report Share Posted March 12, 2011 Man atkal ir aizdomas par informācijas ievākšanu no ārēja resursa :) Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted March 12, 2011 Author Report Share Posted March 12, 2011 (edited) izveidoju šādu koda gabalu, bet liekas ka kaut nav riktīgi, jo neko neatgriež masīvā preg_match_all('/var\skods\s=\s"(\d+)";\svar\snumurs\s=\s"(\d+)";/U', $string, $matches); Edited March 12, 2011 by Rich Bitch Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 12, 2011 Report Share Posted March 12, 2011 Mainīgais ir norādīts?? $x = preg_match_all(); Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted March 12, 2011 Author Report Share Posted March 12, 2011 kāpēc jānorāda mainīgais? izgūtais jau ir arhīvā $matches Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 12, 2011 Report Share Posted March 12, 2011 My bad... Pamēģini var_dump( $matches ). Pamēģini kaut kādu vienkāršāku izteiksmi... Noskaidro kur ir kļūda - pašā izteiksmē vai nē. ) Quote Link to comment Share on other sites More sharing options...
Rich Bitch Posted March 12, 2011 Author Report Share Posted March 12, 2011 izskatās, ka kļūda ir izteiksmē, jo vienkāršas izteiksmes izpildās bez problēmām Quote Link to comment Share on other sites More sharing options...
daGrevis Posted March 12, 2011 Report Share Posted March 12, 2011 Tad salabo izteiksmi! =D Quote Link to comment Share on other sites More sharing options...
marcis Posted March 12, 2011 Report Share Posted March 12, 2011 Neticēju un pat notestēju: <? header('Content-Type: text/plain; charset=utf-8'); $str = ' ... <script type="text/javascript">//<![CDATA[ var kods = "371"; var numurs = "76543210"; document.write(kods + \' \' + numurs) //]]></script> ... '; var_dump($str); $matches = array(); var_dump(preg_match('/var\skods\s=\s"(\d+)";\svar\snumurs\s=\s"(\d+)";/', $str, $matches)); var_dump($matches); ?> Output: string(148) " ... <script type="text/javascript">//<![CDATA[ var kods = "371"; var numurs = "76543210"; document.write(kods + ' ' + numurs) //]]></script> ... " int(1) array(3) { [0]=> string(42) "var kods = "371"; var numurs = "76543210";" [1]=> string(3) "371" [2]=> string(8) "76543210" } 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.