Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 347
  • Last Modified:

HTML forms to MySQL

Dear Experts,

Could I ask a very general, on web pages there can be seen forms where for example a text field can have even 1000 characters long.

Technically when these data are submitted to a MySQL table, basically this all 1000 characters are going to one single field? Or there is some other solution as the length of the fields is limited maybe in MySQL?

thanks,
0
csehz
Asked:
csehz
1 Solution
 
Marco GasiFreelancerCommented:
You can use something like this (found in php.net manual: http://php.net/manual/en/function.substr-replace.php)

<?php
function str_replacer($_string, $_length, $_replacer = ' ...'){
    // Remove any HTML tags present in the string
    $_string = strip_tags($_string);
    if(strlen($_string) > $_length){
        // Find the position for last white space after the string has been shortened to our desired length
        // This helps us to shorten the string without chopping the character or word from the middle
        // ASCII value for the white space is 32
        $_last_white_space_pos = strripos(substr($_string, 0, $_length), 32);
        return substr_replace($_string, $_replacer, $_last_white_space_pos);
    }
    else{
        return $_string;
    }
}
?>

// How to call
<?php
  if (strlen($_POST['text']) > 500) str_replacer($_POST['text'], 500)

 ?>

This function has the advantage to not truncate words

Cheers
0
 
csehzAuthor Commented:
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now