Another preg match question

Discussion in 'PHP' started by Silver89, Nov 21, 2008.

  1. #1
    The commented out part is what I'm trying to match,

    I'm not sure whether to use: preg_match_all or preg_match

    	//<form action="/forums/mostplays/test/"  onsubmit="return validateSubmit()" method="POST" id="comment" name="comment">
    	preg_match_all('~<form action="/forums/(.*)"~i', $siteUrl, $matches);
    	
    		foreach ($matches[1] AS $match)
    		{ 			
    ?>
    	Match: <?=$match?><br /><br />
    <?
            }
    PHP:
    Thanks for the help
     
    Silver89, Nov 21, 2008 IP
  2. french-webbie

    french-webbie Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,
    Not sure what you want to do.

    Do you want to get
    <form action="/forums/mostplays/test/" onsubmit="return validateSubmit()" method="POST" id="comment" name="comment">
    from the $siteUrl variable that can contain anything?
    preg_match('~(<form action="/forums/.*?>)~i', $siteUrl, $matches);

    or do you want to get the 'mostplays/test/' part of the commented line?
    preg_match('~<form action="/forums/(.*?)"~i', $siteUrl, $matches);
     
    french-webbie, Nov 21, 2008 IP
  3. Silver89

    Silver89 Notable Member

    Messages:
    2,243
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    205
    #3
    Yes i'm trying to do the second part of what you wrote, I know how the following but am still not having any luck

    
    	preg_match('~<form action="/forums/(.*?)"~i', $siteUrl, $matches);
    	
    		
    ?>
    	Match: <?=$matches[1]?><br /><br />
    
    PHP:
     
    Silver89, Nov 21, 2008 IP
  4. french-webbie

    french-webbie Peon

    Messages:
    194
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is the code I've tested:

    
    $siteUrl = 'fdfs<form action="/forums/mostplays/test/"  onsubmit="return validateSubmit()" method="POST" id="comment" name="comment">dfdf';
    preg_match('~<form action="/forums/(.*?)"~i', $siteUrl, $matches);
    print_r($matches[1]);
    
    PHP:
    And it returns me
    mostplays/test/
     
    french-webbie, Nov 21, 2008 IP
    Silver89 likes this.
  5. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Im still lost do you just want whats after /mostplays/ ???
     
    atlantaazfinest, Nov 21, 2008 IP