Jump to content

[SOLVED] Automatically make text into a link


christo16

Recommended Posts

Hello All,

Okay so how do I make php search through a $_POST[variable] for a certain set of string, lets say R1000000.  Then I would want to turn that string (R1000000) into a link

<a href=example.php?id="R1000000">R1000000</a>

Then append that link back into the original $_POST[variable] replacing the R1000000, with the link version.

I'm sure this is doable, I just have no idea where to start, regex?

Thank you!!

ok

 

this is an example of how id do it


function link_string($val) {
      $link_format1 = "<a href = '";
      $link_format2 = "' alt = '";
      $link_format3 = "'>";
      $link_format4 = "</a>\n";
      $new_link = $link_format1.$val.link_format2.$val.$link_format3.$val.$link_format4;
      return $val ### not sure about the return, but its either that or return($val)  try it and see

}


foreach($_POST as $key => $val){
      $new_val = link_string($val);
      $_POST[$key] = $new_val;
}

 

 

that code turns avery value in the array into a link... simply change the foreach stuff to select individual elements

 

 

hope it helps

Thank you for the reply,

If anyone was wondering this is how I did it:

Looks for R10000000 and turns it into,

<a href=example.php?id=R10000000>R10000000</a>

 

 $entry_mod = preg_replace("/R[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\b/", 
    "<a href=example.php?id=$0>$0</a>", $_POST["entry"]);

   

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.