quasiman Posted May 26, 2012 Share Posted May 26, 2012 Hey guys, I'm trying to allow users to post their Google Plus game links on my site by just copy pasting them from the stream, and I want to validate what they post before storing it locally. So this is where I'm at so far...ignore the non secure methods at this point, as I'll deal with that when I'm not working locally.... if(isset($_POST['submit'])) { $message = $_POST['messagepost']; $regex = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; if(preg_match($regex, $message, $url)) { // $url is now the array of urls // here you should check $url content and length echo $url[0]; // the first one in this case echo "<pre>"; print_r($url); echo "</pre>"; echo "<hr>"; echo $message; } else { // no urls found echo "no urls found"; } The problem with this script is that it pulls the URL from the first case, which is an image. So the variable $url[0] ends up looking like: https://plus.google.com/games/.....base64encoded params...../source/3"><img So first I need to remove that last bit of text that should not be there: ("><img) There are two URLs in the feed post, one as an image and the other as a basic link....and from the two I have three array items: Array ( [0] => https://plus.google.com/games/.....base64encoded params...../source/3"><img [1] => https [2] => /games/.....base64encoded params...../source/3"><img ) So this is telling me that my regex is wrong, and it's only splitting up the first url (I only posted one image) Quote Link to comment https://forums.phpfreaks.com/topic/263148-preg_match-textarea-with-tinymce-post-array-wrong/ Share on other sites More sharing options...
requinix Posted May 26, 2012 Share Posted May 26, 2012 Your \S is too inclusive. How about making it stop when it hits one of a set of certain characters? Like [^\s"]. Quote Link to comment https://forums.phpfreaks.com/topic/263148-preg_match-textarea-with-tinymce-post-array-wrong/#findComment-1348700 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.