SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Geting a word(s) from a text

    hi
    I have text like this:

    balabalabalabalabalabalabala
    balabalabalabalabalabalabala
    balabala[name]NAME[/name]
    balabalabalabalabalabalabala

    I want to get the word betwen [name] and [/name] and save it as $word for example, how can this be done?

    Thanx
    - m0h

  2. #2
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let's say $string has the text:
    PHP Code:
    if (eregi ("\\[name\\](.*)\\[\\/name\\]"$string$names)) {
      
    $word=$names[1];
    } else {
      
    // name not found


  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to sound like an idiot all the time, but can we please use preg_match()?

    PHP Code:
    preg_match('#\\[name](.+?)\\[/name]#i'$string$names
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope it has been said that preg is way faster than ereg about 5000+ times in this forum.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks.

    Please forgive me, but this is the first regex I've ever written, so be gentle.

  6. #6
    SitePoint Zealot m0h's Avatar
    Join Date
    Sep 2001
    Location
    Cairo, Egypt
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx every one
    - m0h


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
  •