Results 1 to 7 of 7

Thread: find characters that between

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    find characters that between

    How can solve this problem.
    ________________________

    I want code to test if there are any of this characters "+" or ":" or "(" or ")" or "&" between [wor] and [/wor] and give me true else false.

    for example(s):

    $text="hi [wor] : [/wor] bye"; // output >> true

    $text="hi [wor] & how + [/wor] bye"; // output >> true

    $text="hi [wor] can ( [/wor] bye"; // output >> true

    $text="hi [wor] ) [/wor] bye"; // output >> true

    $text="hi ) [wor] you [/wor] bye + & "; // output >> false

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    perhaps something like:


    PHP Code:
    function test($teststr){
    $nStr explode("[wor]"$teststr);
    $pStr explode("[/wor]"$nStr[1]);
    echo 
    $pStr[0];
    if (
    ereg("+"$pStr[0]) || ereg(":"$pStr[0]) || ereg("("$pStr[0]) || ereg(")"$pStr[0]) || ereg("&"$pStr[0])){
        return 
    1;
    } else {
        return 
    0;
    }


  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259
    thanks

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    no worries

  5. #5
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    Prok, do you not understand any of the code we have given you in the past. what you want to do is with regular expressions and it is much faster.

    if (preg_match('/[\+\(\)\&:]/',$string, $match)){
    return 1;
    } else {
    return 0;
    }

    something to that effect.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Posts
    259

    [wor] and [/wor]

    I said provide that text between [wor] and [/wor]

    so use this code:

    <?
    $text="hi [wor] http:// [/wor] ( ";
    $X=preg_match('#\[wor\]((?!\[/wor\]).)*[+)&]((?!\[/wor\]).)*\[/wor\]#i', $text);
    Echo $X;
    ?>


    what is this ? ... that is not the code that I write it it's auto changed ..

    so

    it's here:
    http://www.vbzoom.com/bank/show.php?...leName=PHPBank
    Last edited by prokhaled; Aug 21st, 2002 at 10:57 AM.

  7. #7
    Lively Member scoutt's Avatar
    Join Date
    Aug 2002
    Posts
    84
    well I am impressed. almost got it but not quite.

    Code:
    $text="hi ([wor] http:// [/wor]& bye; ( ";
    if(preg_match('/\[(wor)\].*([:&()+]).*\[/U', $text, $match)){
    echo "found something = ". $match[2];
    }else{
      echo "didn't find anything";
    }
    this will work adn tell you it found something (return true) on the first thing it finds.
    Just Imagine what you can do with the power of php.

    257 Tutorials and counting.
    529 Snippets and growing.

    Add yours today @
    SnippetLibrary.com

Posting Permissions

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



Click Here to Expand Forum to Full Width