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!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"]);

   

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.