Results 1 to 2 of 2
  1. #1

    Simple PHP url parsing... that doesn't work...?

    I've been fooling around with a bit of code lately. It's supposed to convert links like [[link]] in a text to a link like or whatever. Like a Wikipedia link, really.
    Here it is:
    PHP Code:
    while($linkpos strpos($article_text"[["$i) && ($linkpos != FALSE))
    $linkendpos strpos($article_text"]]"$linkpos 1);
    $link substr($article_text$linkpos 2, ($linkendpos 1) - ($linkpos 2));
    $newlink '<a href="' $site_url 'index.php?title="' $link '" class="interlink">' $link '</a>';
    $article_text substr($article_text0$linkpos 1) . substr($article_text$linkpos 1, ($linkendpos 2) - ($linkpos 1)) . substr($article_text$linkendpos 2strlen($article_text) - ($linkendpos 2));
    $i $linkendpos 2;

    Of course, it doesn't work. The text comes out unchanged.

    At the moment, $article_text is the text that is being parsed. $site_url is the url of whatever the site is.

    Anyways, you're probably thinking "What was he thinking when he wrote that code?" or something like that. Well, I'm not that great at PHP. I've never had to do regex or string manipulation before, really. I'm living off of the book until I can get enough experience. And I don't have that much, at the moment.

    Any help would be appreciated. Thanks!

  2. #2
    Never mind. I got it. A simple preg_replace did it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts