Guest User

Untitled

a guest
Nov 16th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. This is a sample tweet https://tr.co/sdfhnjn3
  2.  
  3. This is a sample tweet <a href="https://tr.co/sdfhnjn3">https://tr.co/sdfhnjn3</a>
  4.  
  5. $string = preg_replace('~(?<!href=['"])https?://[w/._-&?]*(?!</a>)(?=[^w/._-&])~gs', '<a href="$0">$0</a>', $string);`;
  6.  
  7. $message = preg_replace('$(s|^)(https?://[a-z0-9_./?=&-]+)(?![^<>]*>)$i', ' <a href="$2" target="_blank">$2</a> ', $message." ");
  8.  
  9. $message = preg_replace('$(s|^)(www.[a-z0-9_./?=&-]+)(?![^<>]*>)$i', '<a target="_blank" href="http://$2" target="_blank">$2</a> ', $message." ");
  10.  
  11. $tweets = [
  12. 'This is a sample tweet https://tr.co/sdfhnjn3',
  13. 'This is a sample tweet <a href="https://tr.co/sdfhnjn3">https://tr.co/sdfhnjn3</a>',
  14. 'This is a sample tweet https://example.com/sdfhnjn3',
  15. 'This is a sample tweet <a href="https://example.com/sdfhnjn3">https://example.com/sdfhnjn3</a>'
  16. ];
  17.  
  18. var_export(preg_replace('~<a [^>]+>.*?</a>(*SKIP)(*FAIL)|https?://(?:www)?tr.co/S*~', '<a href="$0">$0</a>', $tweets));
  19.  
  20. array (
  21. 0 => 'This is a sample tweet <a href="https://tr.co/sdfhnjn3">https://tr.co/sdfhnjn3</a>',
  22. 1 => 'This is a sample tweet <a href="https://tr.co/sdfhnjn3">https://tr.co/sdfhnjn3</a>',
  23. 2 => 'This is a sample tweet https://example.com/sdfhnjn3',
  24. 3 => 'This is a sample tweet <a href="https://example.com/sdfhnjn3">https://example.com/sdfhnjn3</a>',
  25. )
Add Comment
Please, Sign In to add comment