Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

handling long words in php

  • 18-03-2008 02:30PM
    #1
    Registered Users, Registered Users 2 Posts: 648 ✭✭✭


    hi

    ive been looking for a function /way to handle long words entered by users in one of my applications.

    for example if a user enters
    ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss

    then it will distort the page

    how do i introduce a space after ever 20th character if a string goes over a length of 20 ?


    thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,472 ✭✭✭Sposs


    Javascript on the sign form would be your best bet.

    Would allow you to have max limit on the amount of characters.


  • Registered Users, Registered Users 2 Posts: 21,279 ✭✭✭✭Eoin


    Apparently PHP has an in-built function:
    wordwrap($texttowrap, 40, "<br/>", 1);
    

    There is a CSS property, but it only worked in IE 7 for me. I don't know whether it's IE specific or what.
    word-wrap: break-word


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    Sposs wrote: »
    Javascript on the sign form would be your best bet.

    Would allow you to have max limit on the amount of characters.

    but i dont want to limit amount of characters - it will be a testarea that they can add a story to - its the word size im worries about .


    thanks


  • Registered Users, Registered Users 2 Posts: 21,279 ✭✭✭✭Eoin


    Sposs wrote: »
    Javascript on the sign form would be your best bet.

    Would allow you to have max limit on the amount of characters.

    The amount of characters isn't the problem, it's the amount of continuous chracters without a space. If the PHP function doesn't work, you'd probably have to split the text into an array using a space or linebreak as the delimiter, and then iterate through the array and break up any strings.


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    eoin_s wrote: »
    Apparently PHP has an in-built function:
    wordwrap($texttowrap, 40, "<br/>", 1);
    

    There is a CSS property, but it only worked in IE 7 for me. I don't know whether it's IE specific or what.
    word-wrap: break-word


    wordwrap dont work - it only wraps text that has spaces - however u can see my text above has no spaces so this is a no go !
    thanks


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,279 ✭✭✭✭Eoin


    Are you sure? This page says otherwise: http://uk3.php.net/wordwrap


  • Registered Users, Registered Users 2 Posts: 648 ✭✭✭ChicoMendez


    eoin_s wrote: »
    Are you sure? This page says otherwise: http://uk3.php.net/wordwrap


    my bad in fact - i played with the params and yes indeed it works

    thanks lads


Advertisement