php-general Digest 4 Jul 2009 19:45:25 -0000 Issue 6211

Topics (messages 294875 through 294878):

Re: php get rss tag using DOM
        294875 by: Michael A. Peters

Re: Writing to a file
        294876 by: Michael A. Peters

Re: exasperated again
        294877 by: PJ

Love luxury? Buy a fashionable watch.
        294878 by: Leland Finch

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Michael A. Peters wrote:
Rodgerr wrote:


Morris-25 wrote:
Hi,

I am trying to write a programme to read a rss xml file.

...
<media:content url="*exampe.jpg*" ...>
...

    scan anyone tell me how to get the url attribute? I wrote some codes
similar:


 $doc = new DOMDocument;
 $doc->load($myFlickrRss);

 $r = $doc->getElementsByTagName('media:content');
 for($i=0;$i<=$r->length;$i++)  {


$node = $r->item($i);
if ($node->hasAttribute('url') {
 $url[] = $node->>getAttribute('url');
 }


 }

That should give you an array called $url of all the url attributes in the nodes.


$url[] = $node->>getAttribute('url');
should be
$url[] = $node->getAttribute('url');

and don't forget to validate it before spitting it back out on a page somewhere ...
--- End Message ---
--- Begin Message ---
Jason Carson wrote:


Yes, I am trying to write stuff to a file with PHP but in between the
<?php ?> tags and without deleting what is already in the file.



The only way is to read the file into memory, manipulate it there, and then rewrite it.

Use a regex to get rid of the last closing tag, append your new lines to it, and then write it.

You probably want to do it atomic or you can end up with occasional issues (broken pages that requested the file you are writing before it is finished being written) and I don't know if php can do that.

Again that's where using a non php config file that is parsed by php.
You can make your edits, save the file to cache (IE APC) and then write it. Files that need its contents can get it out of cache and only need to read it from file if it isn't cached. Since you cache it before writing, it will be in cache while it is being written.

Another advantage to not using php for the file, you can validate the values before setting/using them and handle problems appropriately in your code rather than have a completely broken site because the script that wrote the file had a bug causing a ; not to be written under certain conditions.
--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
> PJ wrote:
>> Could somebody please explain to me what is wrong with this code?
>> In my script it works, returns the correct id, but when I try it in a
>> test pages, nothing in the world gets it to work. This is rather
>> frustrating, again:
>> THIS WORKS IN ANOTHER PAGE; IN THE TEST PAGE ID DOES NOT.
>> $sql = "SELECT id FROM publishers
>>         WHERE publisher = 'whoever'";
>>       $result = mysql_query($sql,$db);
>>         $row = mysql_fetch_assoc($result);           if
>> (mysql_num_rows($result) !== 0) {
>>           $pub = $row['id'];
>> Syntax is ok, echo "hello"; works.
>>
>>
>> This works in the test page:
>> $aid = array();
>> $ord = array();
>> $sql = "SELECT authID, ordinal
>>         FROM book_author WHERE bookid = 624 ORDER BY ordinal ASC";
>>         $result = mysql_query($sql, $db);             //$row =
>> mysql_fetch_assoc($result);
>>             while ( $row = mysql_fetch_assoc($result) ) {
>>             $aid[]=$row['authID'];
>>             $ord[]=$row['ordinal'];
>>             }
>>             var_dump($aid);
>>             echo "<br />";
>>             var_dump($ord);
>>             echo $aid[0], " - ";
>>             echo $ord[0];
>>
>> This does not:
>> $fi="joe"; $la="joe";
>> $sql = "SELECT id FROM author
>>         WHERE first_name = '$fi' && last_name = '$la'";
>>     $result = msql_query($sql, $db);
>>         $row = mysql_fetch_assoc($result);
>>         $count=mysql_num_rows($result);
>>     echo $count;
>>           if (mysql_num_rows($result) > 0) {
>>           $a_id=$row['id'];
>>           }
>>           echo $a_id, "<br /><br />";
>> The test page prints out echo "some text"; but no results when the
>> results are there....
>> Tell me I have missed something simple here, or is this normal for php ?
>> I have checked the queries on Mysql command line and they are fine.
>> I have verified the syntax and Netbeans tells me it is fine.
>> Same results Firefox3 (2 machines) & IE 8.
>> What is not fine?
>>
>
> I was preaching this to you months ago.  You should have error
> reporting turned on in a development area.
>
> by that I mean php should be set to display_errors = on and
> error_reporting = E_ALL
>
> Give this a try in a development area and "you will see the errors of
> your ways..."
>
The error reporting is always on as you suggested and I use it all the time.
But error reporting cannot report a non-existing error - a human stupid
error that I finally caught - msql instead of mysql... oh. well... :-(

-- 
Hervé Kempf: "Pour sauver la planète, sortez du capitalisme."
-------------------------------------------------------------
Phil Jourdan --- [email protected]
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


--- End Message ---
--- Begin Message ---
You don’t have to save your money for affording a brand watch, as now you can 
get a designer watch at a very funny price. Just order it and we will deliver 
it to you no matter where you are. 
&nbsp;

Visit everybody

--- End Message ---

Reply via email to