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!! Link to comment https://forums.phpfreaks.com/topic/46089-solved-automatically-make-text-into-a-link/ 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 Link to comment https://forums.phpfreaks.com/topic/46089-solved-automatically-make-text-into-a-link/#findComment-223959 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"]); Link to comment https://forums.phpfreaks.com/topic/46089-solved-automatically-make-text-into-a-link/#findComment-224167 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.