SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    breaking string and putting mysql.. please help

    I want to put all words of a string in different rows of a table in mysql. for example.
    $mystring="this is an ugly string"
    i want to put in mysql table like

    id word
    1 this
    2 is
    3 an
    4 ugly
    5 string


    i think first i have to use explode function then use for each loop, but im not able to write the correct sytax, can someone help me with the syntax please ?
    Thanks

  2. #2
    SitePoint Addict ruba's Avatar
    Join Date
    Apr 2005
    Location
    Amman -Jordan
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $mystring="this is an ugly string"
    echo str_replace(' ', chr(10) ,$mystring);
    or 
    echo str_replace(' ' ,'<br>' ,$mystring);
    Open Blocked website
    Open Blocked Website
    Knowledge Is Knowing That A Tomato Is A Fruit,
    Wisdom Is Not Putting It In A Fruit Salad.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try out this code:
    PHP Code:
    $words "this is an ugly string";
    $list split(' '$words);
    foreach(
    $list as $ws){
    echo 
    $ws;

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •