Jump to content


Photo

Selecting A Word In Php String


  • Please log in to reply
4 replies to this topic

#1 mostafatalebi

mostafatalebi

    Advanced Member

  • Members
  • PipPipPip
  • 197 posts

Posted 17 November 2012 - 07:57 AM

Hello every one
I want to write an extensive database for my upcoming bilingual dictionary. I must make my words in a notepad or a text file, and since this job is done by a typist rather than a programmer, I have to tell her to type in a simple format so that using php, later, I could add them to a database. My approach is that to tell her to type words with one space between. Like:

Carrot Potato Bread Water Glass Head Hand Eye Ear Body


What PHP Function or regular expression I must use to get each word into a row of a table in a database?
Visual Effects Programming

Autodesk Maya, Autodesk Mudbox, Nvidia Mental Images Mental Ray, Adobe Photoshop, Adobe Illustrator, Adobe After Effects, CorelDraw

#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,190 posts
  • LocationCheshire, UK

Posted 17 November 2012 - 08:10 AM

explode

eg

<?php
$line = "Carrot Potato Bread Water Glass Head Hand Eye Ear Body";

foreach (explode(' ', $line) as $word) {
echo $word . '<br />';
}

?>

Edited by Barand, 17 November 2012 - 08:10 AM.

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 mostafatalebi

mostafatalebi

    Advanced Member

  • Members
  • PipPipPip
  • 197 posts

Posted 17 November 2012 - 09:27 AM

Oh very clean indeed, thanks. But a question before embarking on a test. Instead of <br /> is it apt to place a mysqli set of commands? thanks
Visual Effects Programming

Autodesk Maya, Autodesk Mudbox, Nvidia Mental Images Mental Ray, Adobe Photoshop, Adobe Illustrator, Adobe After Effects, CorelDraw

#4 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,190 posts
  • LocationCheshire, UK

Posted 17 November 2012 - 11:12 AM

Yes, you can. I was echoing so you could see the result.

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#5 mostafatalebi

mostafatalebi

    Advanced Member

  • Members
  • PipPipPip
  • 197 posts

Posted 17 November 2012 - 01:01 PM

thank you man. working with regular expression are just a way of fun.
Visual Effects Programming

Autodesk Maya, Autodesk Mudbox, Nvidia Mental Images Mental Ray, Adobe Photoshop, Adobe Illustrator, Adobe After Effects, CorelDraw




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com