ziedinjsh Posted July 18, 2012 Report Share Posted July 18, 2012 Sveiki! funkcija function media_check($name){ if($name = preg_replace('/((https?|ftp).*(gif|png|jpg|jpeg))/i', '<img src="$1" />', $name)){ $result = $name; }elseif($name = preg_replace('/([\w\.-]+)(@)([\w\.-]+)/e', '"<a href=\"mailto:\\0\">\\0</a>"', $name)){ $result = $name; }elseif($name = preg_replace('/( http:\/\/)([\w\.-]+)/e', '"<a href=\"\\0\" target=\"_blank\">\\0</a>"', $name)){ $result = $name; }elseif($name = preg_replace('/( www.)([\w\.-]+)/e', '"<a href=\"http://\\0\" target=\"_blank\">\\0</a>"', $name)){ $result = $name; } return $result; } Kapēc viņš linkus nepārkonvertē par hiperlinku? Quote Link to comment Share on other sites More sharing options...
codez Posted July 18, 2012 Report Share Posted July 18, 2012 (edited) Visas šīs regulāro izteiksmu aizvietošanas praktiski vienmēr noved pie xss caurumiem: http://codepad.org/rFjBVQEQ Edited July 18, 2012 by codez Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted July 18, 2012 Author Report Share Posted July 18, 2012 nesapratu. Es nesaprotu kapēc man strādā tikai pirmā rindiņa? Ieliekot vēl sarakstā yutubes video arī nestrādā, bet atsevišķi strādā Quote Link to comment Share on other sites More sharing options...
codez Posted July 18, 2012 Report Share Posted July 18, 2012 tev pirmais if izpildās un nekādi elseif nekad tāpēc neizpildīsies. Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted July 18, 2012 Author Report Share Posted July 18, 2012 kā tad jāveido būt lai viņiem visiem ietu cauri? Quote Link to comment Share on other sites More sharing options...
codez Posted July 18, 2012 Report Share Posted July 18, 2012 rakstot pēc kārtas darbība1; darbība2; darbība3; Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted July 18, 2012 Author Report Share Posted July 18, 2012 un kā tad es varu viņus izvadīt kā vienu? Quote Link to comment Share on other sites More sharing options...
blackhalt Posted July 18, 2012 Report Share Posted July 18, 2012 (edited) un kā tad es varu viņus izvadīt kā vienu? :) Nepārbaudīju vai baigi pareizi darbojas $matches un tā, bet apmēram tā. array() vispirms ņem pirmo, tad otro un tāda garā. <?php function media_check($status_text) { $matches = array( '/((https?|ftp).*(gif|png|jpg|jpeg))/i', '/([\w\.-]+)(@)([\w\.-]+)/e', '/( http:\/\/)([\w\.-]+)/e', '/( www.)([\w\.-]+)/e', ); $replacements = array( '<img src="$1" />', '"<a href=\"mailto:\\0\">\\0</a>"', '"<a href=\"\\0\" target=\"_blank\">\\0</a>"', '"<a href=\"http://\\0\" target=\"_blank\">\\0</a>"', ); $status_text = preg_replace($matches, $replacements, $status_text); return $status_text; } $rinda='blackhalt@gmail.com http://bh.id.lv/epasts.png http://bh.id.lv '; echo media_check($rinda); ?> Edited July 18, 2012 by blackhalt 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.