SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Preg Match Error

    preg_match("/input name=\"(.*?)\" class=\"Enqtxtbox\" type=\"text\"/msU",$html,$n);
    $u=$n[1];
    echo $u;

    this code shows error
    Notice: Undefined offset: 1 in C:\xampp\htdocs\nn.php on line 26

    what is wrong with this code if html code is

    <input class="Enqtxtbox" type="text" maxlength="50" value="" name="dWuGvHeepjNBXHLzMCeZWZ">

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,276
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    $n[1] is undefined because the pattern didn't match, and the pattern isn't matching because you're matching the attributes in a different order.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    can you plz give me right code

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,940
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    Quote Originally Posted by RobinKang View Post
    can you plz give me right code
    What is it you are trying to do exactly?

    Would it be acceptable to test for the presence of "input class="Enqtxtbox", then extract the input's proceeding name attribute?

    E.g.

    PHP Code:
    $subject '<input class="Enqtxtbox" type="text" maxlength="50" value="" name="dWuGvHeepjNBXHLzMCeZWZ">'
    $pattern '/^<input class="Enqtxtbox".*name="(.*?)">$/';
    preg_match($pattern$subject$matches);
    echo(
    $matches[1]); 
    Outputs: dWuGvHeepjNBXHLzMCeZWZ


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
  •