johnrb87 Posted August 5, 2010 Share Posted August 5, 2010 Hi all I wonder if someone can help me, basically I have a HTML form with a free text area, which looks like <textarea name="details"></textarea> when I submit the form, I can print what was outputted using $details = $_POST['details']; print $details; The user is able to either enter plain text, like this is my website profile or they can enter some text and a URL, like this is my website [http://www.google.com,2] profile My question is, when I do my print statement using print $details; how can I get it to convert what has been posted, so that it outputs the following HTML this is <a href="http://www.google.com">my website</a> profile so basically it would create a link using what was entered between [] and then use ,2 to determine how many words before the URL should be linked, so in my example, just the words my website would be linked, as I defined ,2 following the URL in the code. But then further to this, if I entered 0, using ,0 how can I then get it to link all the text, like <a href="http://www.google.com">this is my website profile</a> i'm very new to PHP, so some guidance would be a great help Thanks very very much, been racking my brain on how to do this and have tried so many things, all with massive failure Quote Link to comment https://forums.phpfreaks.com/topic/209850-defining-a-url-from-a-tag/ Share on other sites More sharing options...
sasa Posted August 5, 2010 Share Posted August 5, 2010 try <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ $test = 'this is my website [http://www.google.com,2] profile'; $test = preg_split('/[\[\]]/', $test); $first = explode(' ', trim($test[0])); $url = split(',', $test[1]); $in = ''; if(count($first) < $url[1]) $url[1] = count ($first); for($i =0; $i < $url[1]; $i++){ $in = array_pop($first).' '. $in; } $out = implode(' ', $first). ' <a href="'. trim($url[0]) . '">' . trim($in) .'</a>'.$test[2]; print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209850-defining-a-url-from-a-tag/#findComment-1095448 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.