christo16 Posted April 8, 2007 Share Posted April 8, 2007 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!! Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
christo16 Posted April 8, 2007 Author Share Posted April 8, 2007 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"]); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.