EzDevInfo.com

PHP-Parser

A PHP parser written in PHP

PHP- HTML parsing :: How can be taken charset value of webpage with simple html dom parser?

PHP:: How can be taken charset value of webpage with simple html dom parser (utf-8, windows-255, etc..)?

remark: its have to be done with html dom parser http://simplehtmldom.sourceforge.net

Example1 webpage charset input:

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

result:utf-8



Example2 webpage charset input:

<meta content="text/html; charset=windows-255" http-equiv="Content-Type">

result:windows-255

Edit:

I try this (but its not works):

$html = file_get_html('http://www.google.com/');
$el=$html->find('meta[content]',0);
echo $el->charset; 

What should be change? (I know that $el->charset not working)

Thanks


Source: (StackOverflow)

Limitations of PEG grammar & parser generators?

I was enjoying using YARD a lot:

http://www.ootl.org/yard/

http://code.google.com/p/yardparser/

http://www.codeproject.com/KB/recipes/yard-tokenizer.aspx

I was able to construct fully functional calculator. I'm evaluating YARD to do PHP parser. Please kindly advise on limitations of PEG grammar & parser generators. Thank you very much!


Source: (StackOverflow)

Advertisements

Is it possible to parse PHP using PEG?

The question is very straightforward: Is it possible to parse PHP using PEG? I want to use a PEG parser-generator to parse PHP. Please kindly advise. Thank you!


Source: (StackOverflow)

Finding Content from Javascript using Simple HTML DOM Parser

How do I find the content "Please enter a valid key again" using Simple HTML DOM Parser?

Example:

<script language="javascript">
     function Enable() {      
        alert('Please enter a valid key again');
     }
</script>

This don't seem to work:

<?php

include_once("simple_html_dom.php");

$html = file_get_html("incorrect.html");

$ret = $html->find("Please enter a valid key again", 0);

if ($ret) {
    echo "found";
} else {
    echo "not found";
}
?>

Source: (StackOverflow)

Convert HTML table rows into PHP array and save it to database? [closed]

I'm trying to save a html table rows into php array and then save the array in database.

<form action="" method="post">
        <table class="widefat" id="theTable">
                        <thead>
                                <tr>
                                   <th>Level Identifier</th>
                                    <th>Non-logged in message</th>
                                    <th>Logged in message</th>
                                </tr>
                        </thead>
                        <tbody>

                                  <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                  </tr>

                                   <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                  </tr>

                        </tbody>    
                    </table> 
                </form>

How can i retrieve each row data and save it to array element and finally I would be saving the array to db? Thanks


Source: (StackOverflow)

PHP Simple HTML DOM Parser Call to a member function children() on a non-object

I'm pretty new to PHP, so i try to use Simple HTML DOM Parser to get the information i need from a website. here is the sample node:

<div>
    <h1>Hello</h1>
    <figure id="XXX">
        <div class="abc">ABC</div>
        <div class="qwe">QWE</div>
        <div class="zxc">ZXC</div>
    </figure>
</div>

$element contain above node. What i need to get is the "QWE", so i try:

$name = $element->find('figure[id=XXX]')->children(1)->innertext;

but now the problem: Fatal error: Call to a member function children() on a non-object , that is no problem if i stop at find('figure[id=XXX]'), but it return array and i can't get the exact information.

Any solution? Please help, thanks in advance.


Source: (StackOverflow)

Why embedding functions inside of strings is different than variables

I've asked a question like this before but this one is different, this is more about parsing logic.

My previous questions was about how to embed a function inside of a string (double-quoted) and I received this answer:

$date = "date";
echo "This page is under construction<br/><br/>Current Date: {$date('l jS \of F Y')}";

And after that I started to wonder why this one below is not working while the the one above is working fine:

echo "This page is under construction<br/><br/>Current Date: {date('l jS \of F Y')}";

How is the logic behind the parsing process even though variables are working pretty fine inside of the strings.

I read that after PHP parser $ sign, it tries to find appropriate variable to parse and run and also to delimit the variable name we also use curly braces {} and that is also something I understand fairly.

But why this kind of syntax is seemed required while developing the parser engine for functions because at first it didn't make any sense to me.

Basically, why do I need to define a variable which hold string representaion of the function name such as below:

$date = "date";

Thanks in advance.


Source: (StackOverflow)

Parse Web Page content using PHP

I think it's simple question but I've done what I know and still not work. I want get output from this link :

http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en

You can paste on the browser and look into it. There some text output. I've tried with some function in PHP like file_get_contents and curl. I'm not using ajax or JavaScript because I'm not expert with it. And the last, I'm working with XAMPP.


Source: (StackOverflow)

Parsing JSON Feed

I have a json feed in a URL that contains following data.

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
[{"ID":1123,"OrderNumber":"1394","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"someone.biz/Home/ShowTemplate/283","ShipDate":"2/28/2015","InHomeDate":"3/2/2015","Quantity":"10,000","Price":"$3,000","CallTracking":"0"},{"ID":1123,"OrderNumber":"1413","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"","ShipDate":"3/30/2015","InHomeDate":"3/31/2015","Quantity":"5,000","Price":"$1,500","CallTracking":"0"},{"ID":1123,"OrderNumber":"1413","ProjectType":"Postcard","Template":"WtlossStudy solo","TemplateURL":"","ShipDate":"4/13/2015","InHomeDate":"4/14/2015","Quantity":"5,000","Price":"$1,500","CallTracking":"0"}]
</string>

I need to get it and parse it thorough php. But it is giving invalid foreach error with the following code. Can anyone help me on how to show in correctly.

$json = file_get_contents('http://someurl.biz/api/api/1123');

$obj = json_decode($json, true);

foreach($obj as $ob) {
    echo $ob->ID;
}   

Source: (StackOverflow)

HTML through PHP parser

I'm trying to hide the fact I'm using PHP on one of my site pages and I'm wanting to run it through the PHP parser (just that page not them all) so I can call it filename.html as usual. I have tried a few Apache directives I found online and have a few in my .htaccess file (hotlinks and for a 404 page).

When i use one of the scripts (in my .htacess) for the PHP purpose, the page wants to be saved/downloaded (like a vcard does) and a box shows - with no page to view. Can anyone please help. I'm new to PHP but believe a module might be needed or that it could be to do with the config of my server.


Source: (StackOverflow)

Help with reading javascript output in php

i'm trying to read automatically a javascript output with php, this is the form and the output:

<b>SeteZoom:</b> 
<script>document.writeln(resp)</script> 

<form name=form1 method=GET onSubmit="this.rnd.value=rand()"> 
<input type=hidden name=rnd value=""> 
<b>VocĂȘ:</b> <input type=text name=msg size=30> 
</form>

this is the form and the output is ondocument.writeln(resp), can I read that output with PHP ?


Source: (StackOverflow)

having trouble parsing an array in php

Just starting with php and sorry if this is a newbie question but i'm having problems parsing a array.

I get this value(output of print_r($result);):

Array ( 
  [0] => stdClass Object ( 
       [Master_companyname] => Royal Bank of Canada 
       [ticker] => ry-t 
       [base_table] => Master 
       [base_field] => ticker 
       [set] => 
           [rendered] =>
              Companyname:
              Ticker:
              Companyname:
       [finder_element_1_Master_companyname] => Royal Bank of Canada 
       [field_names] => Array ( 
            [1] => finder_element_1_Master_companyname 
            ) 
       ) 
   )

I want to extract only ry-t but not sure how. Here's what I tried

$result1 = implode('=>', $result);
print_r($result);

and

print (float)substr($result1, strpos($result1, "=")+1);

I studied a bit of java and python and I was trying to apply the same logic of converting it to a string and then splitting the text by a delimiting(in this case I thought "=>").


Source: (StackOverflow)

CSS thru PHP Parser vs. PHP as CSS source

To have my project respond to certain contexts of content, I want my CSS files to respond respectively instead of setting up additional CSS files (adds to http requests) or parsing the CSS right inside the respective php script (imho: quite messy).

CSS thru PHP parser

Now I could tell the PHP parser via .htaccess to treat css files too.
Disadvantages would be: Overhead of processing several css files in my current project-structure OR breaking structure to activate parsing of CSS files just in one subdirectory.
Either way I simply could do it like so:

AddType application/x-httpd-php php php4 php3 css

... vs. PHP scripts as CSS ressource

Or I could link a php source in the page metadata as css source.
Possible disadvantages: May be some browsers won't accept files with different extensions as CSS ressource...?
Anyways...:

<link rel="stylesheet" type="text/css" rel='nofollow' href="/style/preprocessed.css.php" media="all">

What would you suggest?


Source: (StackOverflow)

Two Levels of namespaces in XML parsing with PHP

I have been trying to parse the the title and description from the following XML document (this is just the top part). I have found lots of information about dealing with namespaces but I cannot figure out how to deal with a situation involving getting the content of something that uses names spaces that is the child of something else with a namespace. Any help would be amazing!

<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>2013-10-04T23:19:36Z</responseDate>
<request verb="ListRecords">https://digital.grinnell.edu/drupal/oai2</request>
<ListRecords>
<record>
<header>
<identifier>oai:digital.grinnell.edu:grinnell_166</identifier>
<datestamp>2013-07-02T20:59:30Z</datestamp>
</header>
<metadata>
<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd">
<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">
Grinnell College Young Innovator for Social Justice Prize Award Ceremony, 2011
</dc:title>
<dc:title xmlns:dc="http://purl.org/dc/elements/1.1/">
Young Innovator for Social Justice Prize Award Ceremony, 2011
</dc:title>
<dc:type xmlns:dc="http://purl.org/dc/elements/1.1/">Video</dc:type>
<dc:description xmlns:dc="http://purl.org/dc/elements/1.1/">
An edited recording of the award ceremony for the first Grinnell College Young Innovator for Social Justice Prize.
</dc:description>

The code I have been trying to use for this: Essentially, what I've been trying to do is get the children of the children of the ['oai_dc'] using nested foreach loops.

<?php
$feed = file_get_contents("https://digital.grinnell.edu/drupal/oai2?verb=ListRecords&metadataPrefix=oai_dc&from=2013-06-28&set=islandora_genericCollection");
$xml = new SimpleXmlElement($feed);
foreach ($xml->ListRecords->record as $entry){
  echo $entry->header->identifier;
  echo "<br>";
  echo $entry->header->datestamp;
  echo "<br>";
  //Use that namespace

  $dc = $entry->children($namespaces['oai_dc']);
  foreach ($dc as $dcElement){
    $childern = $dcElement->children($namespaces['dc'])->title;
    echo $children;
    echo "inner loop";
    echo $children->title;
    echo "<br>";
    echo $dcElement->description;


  }
}

?>

Here is sample output (again the XML listed above is only partial the full XML is too long):

oai:digital.grinnell.edu:grinnell_166 2013-07-02T20:59:30Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3268 2013-07-02T23:16:17Z inner loop inner loop oai:digital.grinnell.edu:grinnell_209 2013-07-01T16:36:55Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3269 2013-07-05T23:16:18Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3246 2013-07-17T19:21:41Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3326 2013-07-18T13:22:46Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3249 2013-07-18T13:30:02Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3324 2013-07-18T13:31:01Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3327 2013-07-18T23:16:01Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3328 2013-07-18T23:16:02Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3329 2013-07-18T23:16:02Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3300 2013-08-07T19:28:45Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3256 2013-08-07T19:32:07Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3276 2013-08-07T19:39:05Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3279 2013-08-07T19:42:51Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3281 2013-08-07T19:44:55Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3293 2013-08-07T19:47:21Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3277 2013-08-07T19:50:29Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3257 2013-08-07T19:52:32Z inner loop inner loop oai:digital.grinnell.edu:grinnell_3289 2013-08-07T19:54:31Z inner loop inner loop

Thanks in advance!


Source: (StackOverflow)

Find PHP with REGEX

I need a REGEX that can find blocks of PHP code in a file. For example:

    <? print '<?xml version="1.0" encoding="UTF-8"?>';?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <?php echo "stuff"; ?>
    </head>
    <html>

When parsed would by the REGEX would return:

array(
    "<? print '<?xml version=\"1.0\" encoding="UTF-8"?>';?>",
    "<? echo \"stuff\"; ?>"
);

You can assume the PHP is valid.


Source: (StackOverflow)