0

I am making a simple wiki-style site. I have some text in database and want to make links with [link] tag.

$text = preg_replace('@\[(.*) (.*)\]@', '<a href="\\1" >\\2</a>', $text);

Now I want to change color of the link if the destination page does not exist. How it can be done?

If I insert php code in preg_replace like this:

$text = preg_replace('@[(.*) (.*)]@', '<a href="\\1" class="<?php Wiki::urlchecker($\\1) ?>">\\2</a>', $text); 


it doesnt work, generates:
<a href="link" class="<?php Wiki::urlchecker($link) ?>">Name</a>
briancheg
  • 3
  • 2
  • The detection whether the page exists, or the color thing? – deceze Feb 23 '13 at 18:45
  • 1
    Welcome to Stack Overflow! StackOverflow is not the proper place for this question. We do not write your code for you. You need to do your own coding and if you aren't sure why something is not working as expected, post the code with an explanation of what you were expecting it to do, and what it is actually doing including all error messages. See [about StackOverflow](http://stackoverflow.com/about). – Lightness Races in Orbit Feb 23 '13 at 18:48

1 Answers1

2

Use get_headers to check whether it exists, then use logic to color it with HTML.

This question will show you how to check if the URL exists.

This quetsion will show you how to change the color of a link.

Community
  • 1
  • 1
Kermit
  • 33,827
  • 13
  • 85
  • 121