Solved

HTML forms to MySQL

Posted on 2012-03-29
2
324 Views
Last Modified: 2012-03-29
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
Comment
Question by:csehz
2 Comments
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:csehz
Comment Utility
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now