Web Analytics Made Easy -
StatCounter need help with an IF statement - CodingForum

Announcement

Collapse
No announcement yet.

need help with an IF statement

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • need help with an IF statement

    hi,

    I need to write an IF statement to say IF the length of string of text is more than 34 chars then add '...' to the end

    here is my code which restricts my text string to 34 chars

    PHP Code:
    substr($row1['appliance_fault'],0,34
    here is my attempt of the IF statement

    PHP Code:
    if(substr($row1['appliance_fault'],0,34) <= '34'){
    echo 
    substr($row1['appliance_fault'],0,34).'...';


  • #2
    if (strlen($row1['appliance_fault']) >= 34)

    Are you actually learning anything from us? We keep answering your posts but it kinda seems like you're not using the manual on php.net or any tutorial online. You seem to just come here and ask us to write your project piece by piece.

    Why not put the project up for offer as a job?
    "Tango says double quotes with a single ( ' ) quote in the middle"
    '$Name says single quotes with a double ( " ) quote in the middle'
    "Tango says double quotes ( \" ) must escape a double quote"
    '$Name single quotes ( \' ) must escape a single quote'

    Comment


    • #3
      I'm learning loads here thanks... you lot are very helpful!

      I do refer to php.net manual, I come here as a last resort

      I'm sure I wrote the following piece of code earlier but it didn't work?! ... it does now thanks!

      PHP Code:
      if (strlen($row1['appliance_fault']) >= 34){
                                              echo 
      '<td>'.substr($row1['appliance_fault'],0,34).'...</td>';
                                              } else {
                                              echo 
      '<td>'.substr($row1['appliance_fault'],0,34).'</td>';
                                              } 

      Comment


      • #4
        No, you used substr.

        Yes you are learning lots from us but thats not the best way. The best way is to use a tutorial site, try things and experiment. If it doesn't work look at your code, look up the functions on php.net and see how they work and what they do. Otherwise (as I've noticed this week) all you will do is come here asking us whats wrong and how to fix it - without actually learning. Because we've got your code working you will think that you've learned from us but the next time you go to write code you will find yourself in that "Errrm how do I do that?" scenario.
        "Tango says double quotes with a single ( ' ) quote in the middle"
        '$Name says single quotes with a double ( " ) quote in the middle'
        "Tango says double quotes ( \" ) must escape a double quote"
        '$Name single quotes ( \' ) must escape a single quote'

        Comment


        • #5
          sorry been getting a bit stressed lately as been pressured!

          thanks to everyone who has helped me so far!

          Comment


          • #6
            No worries, glad to have helped
            "Tango says double quotes with a single ( ' ) quote in the middle"
            '$Name says single quotes with a double ( " ) quote in the middle'
            "Tango says double quotes ( \" ) must escape a double quote"
            '$Name single quotes ( \' ) must escape a single quote'

            Comment

            Working...
            X
            😀
            🥰
            🤢
            😎
            😡
            👍
            👎