Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default ereg problem

    Can any of you kind people tell me what I'm doing wrong?

    An example:
    $code="<gateway>FooBar</gateway>";
    $var="gateway";

    I am trying to get the FooBar information from the $code by passing $var and
    $code to a regular expression:
    $value=eregi("<$var>[a-zA-Z0-9 ]<$var>", $code, $value);

    I am trying to make $value contain FooBar.


    Regards
    Richard Grove
    [url]http://www.shopmaker.co.uk[/url] - UK Ecommerce Shop Systems



    Richard Grove - ®ed Eye Media Guest

  2. Similar Questions and Discussions

    1. ereg
      Hi! I'm working with ereg and mails now. Does represent only A-Z, 0-9 or something more? And if yes, ther what? TIA RuBenz
    2. [PHP] Bug in Ereg?
      ow .. this script won't work .. checkboxes like this: <input type=checkbox name="colors" value="on"> or var calling like this: $_POST ...
    3. Bug in Ereg?
      Hi, I have a form with checkboxes that POSTs to a PHP script. What is posted : _POST on _POST on _POST on
    4. [PHP] ereg problem?
      chenqi1@zte.com.cn wrote: It's looking for a \ character or a \ character followed by the letter n anywhere within the string $username. --...
    5. ereg problem?
      who can tell me what's the pattern string mean. if(ereg("",$username)) { /*Do err*/ }
  3. #2

    Default Re: ereg problem

    > Can any of you kind people tell me what I'm doing wrong?
    >
    > An example:
    > $code="<gateway>FooBar</gateway>";
    > $var="gateway";
    >
    > I am trying to get the FooBar information from the $code by passing $var
    and
    > $code to a regular expression:
    > $value=eregi("<$var>[a-zA-Z0-9 ]<$var>", $code, $value);
    >
    > I am trying to make $value contain FooBar.
    >


    No worries, I've sorted this now:

    if(eregi("<$var>(.*)</$var>", $code, $out)) {
    $value = $out[1];
    }
    $value=eregi_replace("<$var>","",$value);
    $value=eregi_replace("</$var>","",$value);


    > Regards
    > Richard Grove
    > [url]http://www.shopmaker.co.uk[/url] - UK Ecommerce Shop Systems

    Richard Grove - ®ed Eye Media Guest

  4. #3

    Default Re: ereg problem

    Richard Grove - ®ed Eye Media wrote:
    >>Can any of you kind people tell me what I'm doing wrong?
    >>An example:
    >> $code="<gateway>FooBar</gateway>";
    >> $var="gateway";
    [snip]
    >
    > No worries, I've sorted this now:
    >
    > if(eregi("<$var>(.*)</$var>", $code, $out)) {
    > $value = $out[1];
    > }
    > $value=eregi_replace("<$var>","",$value);
    > $value=eregi_replace("</$var>","",$value);
    Why not try a more generic solution e.g.:

    $code="<gateway>FooBar</gateway>";
    preg_match("/<([^>]+)>([^<]+)<.*/",$code,$match);

    where $match is an array containing:
    0=> FooBar (full patern match)
    1=> gateway (first parenthesis)
    2=> FooBar (second parenthesis)

    now you could do:

    $$match[1] = $match2;

    wich would resolve in $gateway="FooBar"

    HTH
    carlos
    carlos Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139