开发者

php regular form and input

I want to get the search box from this site, I use php regular the form part, but there still has many othe开发者_JS百科r html code in it. So how to remove them and just get a pure search box? Thanks.

<?php
$str = file_get_contents('http://bingphp.codeplex.com');
preg_match_all('~<form.+</form>~iUs', $str, $match);
var_dump($match);
?>


Should use DomDocument parser ?

$dom = new DomDocument;
libxml_use_internal_errors(true);
$dom->loadHTMLFile('http://bingphp.codeplex.com/');
$nodes = $dom->getElementsByTagName('form');
foreach ($nodes as $node)
{
  echo simplexml_import_dom($node)->asXML();
}

PS

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


If you only want the search box. why not using your own search box ?

<form action="http://bingphp.codeplex.com/Wiki/Search.aspx" method="GET">
    <input type="hidden" name="tab" value="Home" />
    <input type="text" name="SearchText" value="PHP" />
    <input type="submit" value="Let's vamp the search" />
</form>

I'm not even sure the hidden input must be here (depends if they check it on their side).


You might want to try and create your own form with the same fields and just change the action attribute to the same action target of the original site.

It won't always work though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜