Jump to content

Recommended Posts

lol why are you using preg_split?  preg_split is a regex version of explode.  All it does is take a string and split it up into an array, based on a pattern.  So for example, if you have this:

 

$string = "What's up, doc? Nothin' much, man...";

 

and you do this:

 

$string = preg_split("/[\s.,_\"\'\%\>\<?!-]/", $string);

 

You're going to end up with this:

 

Array
(
    [0] => What
    [1] => s
    [2] => up
    [3] => 
    [4] => doc
    [5] => 
    [6] => Nothin
    [7] => 
    [8] => much
    [9] => 
    [10] => man
    [11] => 
    [12] => 
    [13] => 
)

 

Unless you are wanting your data to be a specific format (like for instance, the data is a username and you only want it to contain alphanumeric characters), the goal should be to escape characters, not remove them.  Otherwise, you're going to find yourself storing a whole lot of swiss cheesed data.

:D I know! The string is as search string, I choose to separate the words to do a mySQL full text AND search (Search Word1 AND Word2 AND Word3, etc..). All words on the string must appear on the results.

 

That is the reason I want to prevent SQL injection and exploits. Because the string is directly input on the database. So I guess, if only ' is necessary to be cut down I could do it like this (with the other %>< while I'm at it, just to be sure  ;D)?

 

preg_split("/[\s.,_'%><?!-]/", $kernel->vars['string']);

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.