Jump to content

preg_match textarea with tinymce post - array wrong


quasiman

Recommended Posts

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)

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.