Solved

HTML forms to MySQL

Posted on 2012-03-29
2
325 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 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 37781746
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
ID: 37782612
Thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

920 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

16 Experts available now in Live!

Get 1:1 Help Now