cucumber Posted March 16, 2008 Report Share Posted March 16, 2008 Ka var javascript f-jai padot mainigo stringu, kura ieksha ir pareja(s) uz jaunu rindu? Link to comment Share on other sites More sharing options...
andrisp Posted March 16, 2008 Report Share Posted March 16, 2008 Funkcijai var padot kā jebkuru citu parametru. Vai ari konkreetaak apraksti savu probleemu. Link to comment Share on other sites More sharing options...
cucumber Posted March 16, 2008 Author Report Share Posted March 16, 2008 es no elementa izsaucu javascript f-ju, kura ka mainigo padotu $string = 'abc\nabc\naaaa', uz tekstu ar pareju jauna rinda paradas kluda? <div onclick="java script:openPopup('$string');">spied</div> Link to comment Share on other sites More sharing options...
andrisp Posted March 17, 2008 Report Share Posted March 17, 2008 Kāda kļūda ? Un kā tieši uzskatās uzģenerētais HTML ? Link to comment Share on other sites More sharing options...
cucumber Posted March 17, 2008 Author Report Share Posted March 17, 2008 (edited) Kluda tada ka nevar padot funkcijai tada veida mainigo? <script> function getText(string) { alert(string); } </script> <?php $string ="abc\nabc\nabc\n"; echo "<div onclick=\"java script:getText('$string');\">spied</div>"; ?> izsaucot f-ju paradas :: Error: unterminated string literal (ff devtolbara) Edited March 17, 2008 by cucumber Link to comment Share on other sites More sharing options...
Aleksejs Posted March 17, 2008 Report Share Posted March 17, 2008 $string tiek aizpildīts PHP pusē, vai ne? Vai nesanāk, ka HTMLS pēc $string = 'abc\nabc\naaaa'; izskatās šādi: <div onclick="java script:openPopup('abc abc aaa');">spied</div> ?? Ja tā, tad varbūt pamēģini: $string = 'abc\\nabc\\naaaa'; Link to comment Share on other sites More sharing options...
cucumber Posted March 17, 2008 Author Report Share Posted March 17, 2008 Nezini vai tas butu tas risinajums, bet ja $string ="abc\\nabc\\nabc\\n"; pirms \n pieliek vel vienu \, tad strada. Link to comment Share on other sites More sharing options...
Aleksejs Posted March 17, 2008 Report Share Posted March 17, 2008 Jap :) Link to comment Share on other sites More sharing options...
cucumber Posted March 17, 2008 Author Report Share Posted March 17, 2008 (edited) Tad ka php puse vajag apstradat maingo, lai to varetu padot f-jai bez problemam (\n, ' , ") likt prieksha \ un viss? it ka der. function jsspecialchars($s) { return preg_replace('/([^ !#$%@()*+,-.\x30-\x5b\x5d-\x7e])/e', "'\\x'.(ord('\\1')<16? '0': '').dechex(ord('\\1'))",$s); } Edited March 17, 2008 by cucumber Link to comment Share on other sites More sharing options...
Aleksejs Posted March 17, 2008 Report Share Posted March 17, 2008 Jāescapo visi \ Bet vispār savādi... jo konstrukcijai $mainigais = 'kaut\nkas'; vajadzēja mainīgo uzstādīt kā: kaut\nkas , nevis: kaut kas http://lv.php.net/manual/en/language.types.string.php Jo šādi vajadzētu darboties tikai pēdiņām, nevis apostrofiem. Respektīvi, ja būtu uzstādīts $mainigais = "kaut\nkas"; Link to comment Share on other sites More sharing options...
andrisp Posted March 17, 2008 Report Share Posted March 17, 2008 Aleksejs, neesmu pārliecināts, bet man liekas, ka vienpēdiņās ņulainus un pārējos arī ņēma vērā. PHP kodu gan ne. Link to comment Share on other sites More sharing options...
Aleksejs Posted March 17, 2008 Report Share Posted March 17, 2008 Nu, pēc dokumentācijas: // Outputs: This will not expand: \n a newline echo 'This will not expand: \n a newline'; Bet dabā, nezinu kāpēc, bet viņš tomēr "expando" to \n simbolu Link to comment Share on other sites More sharing options...
indoom Posted March 18, 2008 Report Share Posted March 18, 2008 (edited) Tāpēc, ka cucumber izmanto dubultpēdiņas PHP variablī. Izmantojot 'abc\nabc\nabc\n' nav jāslešo newlines <?php $string ='abc\nabc\nabc\n'; echo "<div onclick=\"java script:getText('$string');\">spied</div>"; ?> Edited March 18, 2008 by indoom Link to comment Share on other sites More sharing options...
andrisp Posted March 18, 2008 Report Share Posted March 18, 2008 Bet dabā, nezinu kāpēc, bet viņš tomēr "expando" to \n simbolu Aleksej, bet tu pamēģināji to kodu izpildīt ? "Neekspando" taču tomēr :) Link to comment Share on other sites More sharing options...
Recommended Posts