Displaying & formatting text with mysql database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    Displaying & formatting text with mysql database

    I need some help with formatting some text received from a database
    query. I am only selecting a single row per query so the formatting
    will only be performed on a single row. The rows I need to format
    upon display to the user are currently in text like so: word1 word2
    word3 word4 (note there are only spaces between each word)

    I just want to insert a character between each word when displayed. A
    dash, for example. I want it to look like this: word1 - word2 - word3
    - word4 etc. Its too late to do it b4 I put it in the database, so I
    have to do it now. Any ideas?

    TIA
    Rob
  • Tom Thackrey

    #2
    Re: Displaying & formatting text with mysql database


    On 7-Oct-2003, gojuka@si.rr.co m (Robert) wrote:
    [color=blue]
    > I need some help with formatting some text received from a database
    > query. I am only selecting a single row per query so the formatting
    > will only be performed on a single row. The rows I need to format
    > upon display to the user are currently in text like so: word1 word2
    > word3 word4 (note there are only spaces between each word)
    >
    > I just want to insert a character between each word when displayed. A
    > dash, for example. I want it to look like this: word1 - word2 - word3
    > - word4 etc. Its too late to do it b4 I put it in the database, so I
    > have to do it now. Any ideas?[/color]

    I'm not totally clear on the question but try this:

    // assuming $row has been retrieved from the database
    $fieldwithdashe s = str_replace(' ',' - ',$row['fieldname']);
    echo $fieldwithdashe s;

    --
    Tom Thackrey

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Matthias Esken

      #3
      Re: Displaying & formatting text with mysql database

      "Tom Thackrey" <use.signature@ nospam.com> schrieb:
      [color=blue]
      > // assuming $row has been retrieved from the database
      > $fieldwithdashe s = str_replace(' ',' - ',$row['fieldname']);[/color]

      I just wanted to post something with regular expressions. Glad you were
      first. :-)

      Regards,
      Matthias

      Comment

      Working...