We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32614
    • 65 Posts
    i’m wondering if anyone knows how to make full urls left in my comments turn into actual links, like bbcode does.

    thanks for any tips!
      "A great democracy must be progressive, or soon it shall cease to be great, and soon it shall cease to be a democracy." -Theodore Roosevelt
      • 18397
      • 3,250 Posts
      It shouldn’t be too hard. Anyone know the line of code bbcode uses to accomplish this?
        • 18397
        • 3,250 Posts
        Ahah! Found one:

         $output[1] = preg_replace("/\b((http(s?):\/\/)|(www\.))([\w\.]+)([-~\/\w+\.-?]+)\b/i", "<a href=\"http$3://$4$5$6\" target=\"_blank\">$2$4$5$6</a>", $output[1]); 
        
        • You can also check out some regular expressions from other formatters. Here is an example from my EtoWiki snippet I developed when using Etomite months ago (based on roWiki) for doing even more than just converting text links, if you’re interested:

          	$wikiOutput = preg_replace("/&#036;/Umsi", "$", $wikiOutput);
          	$wikiOutput = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&,\+]*)\]#U', '<a href="xx$2">$1</a>', $wikiOutput);
          	$wikiOutput = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $wikiOutput);
          	$wikiOutput = preg_replace('#(https?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*)#i', '<a href="$0">$1</a>', $wikiOutput);
          	$wikiOutput = preg_replace('#xxttp#', 'http', $wikiOutput);
          	$wikiOutput = preg_replace("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", "<a href=\"$wikiDocLink?page=$1\">$1</a>", $wikiOutput);
          	$wikiOutput = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $wikiOutput);
          	$wikiOutput = preg_replace('/^\*(.*)\n/Um', "<ul><li>$1</li></ul>", $wikiOutput);
          	$wikiOutput = preg_replace('/^\#(.*)\n/Um', "<ol><li>$1</li></ol>", $wikiOutput);
          	$wikiOutput = preg_replace('/(<\/ol><ol>|<\/ul><ul>)/', "", $wikiOutput);
          	$wikiOutput = preg_replace('/^!!!(.*)(\n)/Um', '<h4>$1</h4>', $wikiOutput);
          	$wikiOutput = preg_replace('/^!!(.*)(\n)/Um', '<h5>$1</h5>', $wikiOutput);
          	$wikiOutput = preg_replace('/^!(.*)(\n)/Um', '<h6>$1</h6>', $wikiOutput);
          	$wikiOutput = preg_replace('/----(\r\n|\r|\n)/m', '<hr />', $wikiOutput);
          	$wikiOutput = preg_replace('/\n/', '<br />', $wikiOutput);
          	$wikiOutput = preg_replace('#(</h[123]>)<br />#', "$1", $wikiOutput);
          	$wikiOutput = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $wikiOutput);
          	$wikiOutput = preg_replace("/'''(.*)'''/Um", '<strong>$1</strong>', $wikiOutput);
          	$wikiOutput = preg_replace("/''(.*)''/Um", '<em>$1</em>', $wikiOutput); 
          


          I’d really like to see a Textile or 37 Signals style formatter integrated fully with MODx as a plugin!
          • I think 37 Signals is Markdown or Textile actually.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 6726
              • 7,075 Posts
              There is a Textile Beta plugin. I still have to take the time to test it, being Textile savvy smiley

              But textile does not auto-convert urls into links. Those EtoWiki regular expressions are a good idea smiley I also like the idea of auto-acronyms, very useful.

              Markdown should be easy to port with phpMarkdown
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l&#39;outil id