Can $node->node_value() Return A Null Value?
I am using the following function to access a nodes value from an XML
file. It works fine until it discovers a empty tag. I would like to
have the option of leaving some tags empty for my script.
..
..
..
function foutput_contact ($node_name) {
$xml_document = domxml_open_file('xml/contacts.xml');
if ($xml_document) {
$nodes= $xml_document->get_elements_by_tagname($node_name);
$nodeCount = count($nodes);
$node = $nodes[0];
if ($node) {
$node = $node->first_child();
return $node->node_value();
}
}
}
The error is returned at the line 'return $node->node_value()' but
only when I use an empty node. Can this script be modified to allow
empty nodes?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Why Would Socket_read() Return NULL Character But Not Fail?
I've got a PHP script plotting data in a PNG image. For each parameter it needs to plot, it opens a socket connection to another server, asks for data, plots it, then closes the socket. Now the first parameter always succeeds no problem. However for the next iteration, it always gives me a NULL character (socket_read() returns true). Now if I just socket_read() again, all the data is there and waiting. The server on the other end doesn't flag anything unusual, no writes() to the socket fail, etc. I've tried adding sleep() for both client and server, thinking it was some timing or race condition, but that didn't seem to help in any way. Has anyone seen socket_read() return true, but return only a single NULL character? According to php.net manual, socket_read() might return an empty string "" with length 0 if the connection is reset by peer, but that's not what I'm seeing here (I don't think).
XML - Node Manipulation
I was wondering if anyone could point me to any references regarding manipulating XML Child Nodes. I am currently retrieving data from XML in a manner that is useful. However, I am scratching my head when I need to change that information.
Select Node From DOM By ID?
I'm looking for a way to select a <div> by id from an entire xhtml page. I'm not a very experienced coder, but I'm learning... Does php have a fuction for this? it would be like $entire_page = "entire xhtml page fetched from DB which contains <div id='wanted_div'>some content I want</div>"; $my_wanted_div = .... // how do I get the content of 'iwantthisdiv' here?
Children Of Child Node??
Is there any function or way to access the children of a child node using DOM??? I mean if i have the xml structure as: <app> <app_data> <data name='method'><value>sum_dif</value></data> <data name='val1'><value>123</value></data> <data name='val2'><value>456</value></data> <app_data> // child of child node <data name='coool'><value>divo9</value></data> <data name='sands'><value>007</value></data> <data name='make'><value>bond</value></data> </app_data> </app_data> </app> How can I access the data in the child node <app_data>?
Writing A Node To An XML File
I want to write a node or nodes to an existing xml document. I don't need to create a new document, thanks but no thanks. Judging from various posted topics I've seen. It appears the php DOM for XML isn't quite there yet and has a lot of bugs. Not only that it takes a few months before web hosters update versions of php. I tried the pear classes, but they're so poorly documented, there's no example, there's nobody you can contact at Pear for hlep. If you ask for help on forums, you get no reply's so obviously not many ppl are using these classes. I wonder..... if there's a push from say mySQL to stall or slow down PHP's functionality for XML? Any ideas on how to write a node or nodes into an existing XML file..... without a bunch a array manipulation?
Deleting A Node With Known Position In DOM (XML)
I have a a xml with a very basic structure: <root> <template name="name0">data0</template> <template name="name1">data1</template> <template name="name2">data2</template> <template name="name3">data3</template> <template name="name4">data4</template> <template name="name5">data5</template> <template name="name6">data6</template> </root> I'm trying to remove the 4th node in the file (named name3). The code i'm using for this is: <? $i = 3; //Hoping to delete the 4th node. $doc = new DOMDocument(); $doc->load('file:///var/templates.xml'); $items = $doc->getElementsByTagName('template'); $items2 = $items->item($i); $itemg = $items2->nodeValue; echo $itemg; //It does return the value of the item i'm trying to delete. $itemg = $items->removeChild($items2); //Return: "Fatal error: Call to undefined method DOMNodeList::removeChild()" ?> As said above, the script return Fatal error: Call to undefined method DOMNodeList::removeChild(). I've no idea why it isn't working, and definitely not an idea what the correct code would be.
DomDocument: Setting Attributes To A New Node
I'm trying to create a single function to append new nodes to a DOMDocument object: public function addElement( $element, $name, $value = '', $attrs = Null ) { if( !( $created = $this->createElement( $name, $value ) ) ) throw new Exception( 'Could not create a new node ' ); if( !( $child = $element->appendChild( $child ) ) ) throw new Exception( 'Could not append a new node ' ); // Process and attachs the new attributes from array $attrs if any... // if( $attrs ) // foreach( $attrs as $attribute => $value ) // ... } So far, so good. Now I want to set attributes and its values of the recent created node (playing with createAttribute() and setAttribute(), but I can't get the DOMElement from the new child DOMNode. Is it possible without issuing getElementsByTagName() or getElementById() ?? Is another easy way -using DomDocument object- to create a new element (such <table width="50%" border="0">...</table>) which has its attributes and its values ?
After I Load An XML File, Can I Sort It By Node Attribute
After loading an xml file, is it possible to sort it by attribute? For example, I have the following xml file: <xml... <diary> <entry date="2005-01-01">I went to the park</entry> <entry date="2005-01-03">Sold the car today</entry> <entry date="2005-01-02">Went for a stroll</entry> </diary> When I go to load this using PHP, I would use some this similar to this: $xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS); $node = $xmldoc->document_element(); Before I go storming through the xml tree outputing along the way, can I sort it by (in this case) date?
[DOM XML] How To Encode A Node Content (Accentuated Characters)
I'm trying to generate a RSS newsfeed using the DOM XML functions. However I can't find a way to use accentuated characters. I even tried to specify a character encoding set but it doesn't solve the problem. Error I get : XML Parsing Error: not well-formed Location: news.php?action=syndicate&format=rss2 Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss version="2.0"><channel><title>Website title - News ( ---------------------------------------------------------------------------- -----------------------------------------------------------^ The not well-formed character is an accentuated character, as you can see on the following code sample : <?php header ('content-type: text/xml'); echo ('<?xml version="1.0" encoding="ISO-8859-15"?>'); $dom_doc = domxml_new_doc (Ƈ.0'); $rss_el = $dom_doc->create_element ('rss'); $rss_el->set_attribute ('version', ƈ.0'); $rss_el = $dom_doc->append_child ($rss_el); $channel_el = $dom_doc->create_element ('channel'); $channel_el = $rss_el->append_child ($channel_el); $title_el = $dom_doc->create_element ('title'); $title_el = $channel_el->append_child ($title_el); $title_el->set_content ('Website title - News (àéèù)'); echo ($dom_doc->html_dump_mem ()); ?> Removing the accentuated characters from the title generates a well formed XML file. Note that I also tried to encode the characters using the htmlentities function but it didn't change anything.
Zero And NULL
I have the following switch statement: switch ($record->sub_page) { case -1: $this->page = 6; $error_message = '<center>You appear to have already completed the form.</center>' break; case 0: $this->page = 5; ff_query("UPDATE #__gateway_form_1 SET `sub_page`=-1 WHERE userid=$my->id and `expiry_date` = '$expiry_date'"); break; default: do something else } The value of $record->sub_page can be NULL. If it is NULL, the case for 0 seems to fire. I really need the default action to happen when $record->sub_page is NULL or a +ve value. However if I do: switch ($record->sub_page) { case -1: $this->page = 6; break; case NULL: do something else; break; case 0: $this->page = 5; break; default: do something else; } then the switch manages to tell the difference between a NULL and a zero. Is it correct that php treats NULL as 0?
NULL Or NOT NULL
I'm using GROUP BY in a MySQL query to return rows of scores based on the values held in a field. The query prints the value that applies to each row, and then the score - the number of records with that value. It works, but I'm finding that one of the rows shows no value but does show a score, as if there are some empty cells in the database (there are too many results to be able to go into the database and actually see those empty cells). Whether I reset the field to NULL or NOT NULL (in phpMyAdmin) makes no difference - the empty cell score is displayed either way. Seems odd to me, so I am trying to get a better understanding of when to specify NULL and NOT NULL and how to construct a query in such a way as to exclude cells with no data. Technically, if I want to exclude results where a cell contains no data, what combination should I be using? Currently my query is ....
If Null
I'm sure this is very simple, but I'm just getting started with php and mysql and was wandering if someone could help me with a snipped of code. I have a page that displays information from my database. One of the items it displays is an image. like this: <img src="<?php echo $row_Businesses['logo_url']; ?>" alt="<?php echo $row_Businesses['name']; ?>" width="100" height="100" border="1" /> Now, not all of the rows in my database have an entry for 'logo_url' and are null. I would like it so that if 'logo_url' is null it will instead show an alternative image called nologo.gif I imagine it would be along the lines of if 'logo_url' = null show nologo.gif else show <?php echo $row_Businesses['logo_url']; ?>.
How Does NULL Work?
Here's what I have: A table with several rows. Each row has 11 columns... The first column is the unique ID. The remaining ten are varchar columns meant to hold the filename of a given image (for instance [primarykey]1.jpg, [primarykey]2.jpg, etc.) I then have a javascript photo browser, where each photo name is loaded dynamically into a list with a repeating region assigned: <option name="<php code here>"> This all works fine, however, not all rows have 10 photos. So, I need to know how NULL works. Can I code my option list so that it will not insert another entry if the corresponding field is NULL?
What Is Better As A Default Value: NULL Or ''?
I would like to collect some statistical data and then make some reports on it. I'm creating tables for this task and i'm not sure what is better for filling default values: NULL or ''. What is optimal for storage purposes and for further reports creation?
Argv[0] Always Null
In my PHP, argv[0] always return correct value. In a remote server, PHP returns for argv[0] always null. I believe this is a "php.ini" problem but from PHP help I don't found anything. 1. What is the problem? 2. How to fix it? (or...) 3. With what I can replace argv[0]?
Differentiate Between NULL And 0
I have a script which takes the results of a form and updates or creates a record in a db table. So far so dull. It works fine, except when I leave certain fields blank; these are entered in the table as zero values. Can anyone assist me to differentiate between NULL and zero? the variables that are troubling are fatalities, injuries, latitude and longitude. code: # load variables into array $variables["type"] = $type; $variables["location"] = $location; $variables["fatalities"] = $fatalities; $variables["injuries"] = $injuries; $variables["latitude"] = $latitude; $variables["longitude"] = $longitude; $variables["development"] = $development; $variables["list"] = $list; $variables["display"] = $display; $variables["description"] = $description; foreach ($variables as $key => $value) { # loop through variables; $element =& $variables[$key]; if (isset($value)) { # if variable is not null, add quotes for sql query $element = "'" . $element . "'"; } else { # variable is NULL - no quotes $element = "NULL"; } unset($element); } # explode array back to variables extract($variables); if(isset($eventID)) { # updating an existing record # create SQL from variables $sql = " UPDATE tblevents SET enumType = $type, locationID = $location, datDate = '$eventDate', intFatalities = $fatalities, intInjuries = $injuries, dblLatitude = $latitude, dblLongitude = $longitude, developmentID = $development, enumList = $list, enumDisplay = $display, txtDescription = $description WHERE eventID = $eventID "; }
PHP Null Values
NULL is converted to blank in php array when i use mysql_fetch_array . I want something where NULL remains as it is in php array.
HTTP_REFERER Is Null
I have a normal HTML link on an html page on one site pointing to a test.php file on another site. I want to get the URL of the refering page using PHP, but have so far been unsuccessful. Both $_SERVER['HTTP_REFERER'] and getenv('HTTP_REFERER') provide null results. Also, phpinfo() does not display the HTTP_REFERER. I can successfully get the remote IP addresses with $_SERVER['REMOTE_ADDR']. JavaScript successfully displays the correct refering URL with: <script language=javascript>document.write(referer);</script> so, apparently, the header information is available. I have tried this with MSIE and Firefox browsers. I have also placed the test.php file on two different servers, but in each case PHP failed to find the refering URL.
Preg_match - How To Match X00 (null)?
I'd like to work with a binary file.... I read the whole file into variable (it conatains binary data from 00-FF): $fp=fopen($cfg,"r"); $content=fread($fp,filesize($cfg)); fclose($fp); // and then I'd like to check if it contains special binary sequence, let's say bytes "00 01 02 03": $replacestring="/x00x01x02x03/im"; if (preg_match($replacestring,$content)==0) { echo("bad input file format"); exit(); } but i get error message: <b>Warning</b>: preg_match(): No ending delimiter '/' found in <b>test.bat</b> on line <b>57</b><br /> I think it is maybe because php uses strings terminated with null, but can i force php to use strings with predefined length for example? Is there a way to work with strings containing null characters?
NULL Expected, Won't Show Up ...
I have tho following code. $_GET['artile'] looks like this: /2006/03/lorem_ipsum $locationinfo = explode('/', trim( $_GET['article'] , '/') ); list( $article_year, $article_month, $article_url ) = $locationinfo; echo '<br>year: '.(($article_year === NULL)? 'null': $article_year); echo '<br>month: '.(($article_month === NULL)? 'null': $article_month); echo '<br>article: '.(($article_url === NULL)? 'null': $article_url); The weird thing is, if $_GET['article'] is empty, $article_year isn't NULL, but the rest is. This doesn't make any sense to me ...
Returning A Null Reference In PHP 4.4.2
Consider a class that encapsulates an associative array. It has two "setter" methods: class A { .... function setAttribute( $name, $value ) { $this->attributes[ $name ] = $value; } .... function setAttributeByRef( $name, &$value ) { $this->attributes[ $name ] =& $value; } .... The following "getter" method *used* to work just fine prior to version 4.4.2: .... function & getAttribute( $name ) { if ( isset( $this->attributes[ $name ] ) ) return $this->attributes[ $name ]; return NULL; } .... However, as of version 4.4.2, this throws a "FATAL: Only variable references should be returned by reference." error. Unfortunately, my host (and several of my client hosts) are stuck on this version. Is there an elegant way to solve this problem? I want to return a value indicating that no such attribute exists. (I've googled the problem and can't find anything useful other than a suggestion in a PHP bug report that I learn how to write "proper" code.)
MYSQLI: Null Value In Bind_param() ??
Could anyone tell me if it is possible to bind a null value to a statement? I.E. $stmt->bind_param('isd',$var1,$var2,$var3); $var1 = (something indicating null); $var2 = (something indicating null); $var3 = (something indicating null); This would be useful as I have form fields that are not required and link to database fields that allow nulls. It would be nice to include all fields in the statement but assign a null value to fields for which the user did not fill in the corresponding form element.
NULL Values In A Record
i was wondering if a record has a NULL value, can i define an if-else statement to avaod displaying it? for example if ($array[field] == NULL){ display nothing} i'm trying to display lyrics of an album and some songs don't have lyrics.
Insert Null Date
I made a form to put data into a mysql database. When a date record from the form is empty, it errors out. The text records have no problem if they are blank. How can I make my database able accept blank records for a date? I know more info might be needed but I'll wait for you guys to tell me what you need to know.
Radio Buttons And Use Of NULL
I am developing a survey that has a bunch of mainly radio buttons. The radio buttons are for selections Disagree Strongly through Agree Strongly which I have assigned values 1-5, and a N/A selection. If nothing is entered, or N/A is selected, I want NULL to be entered into the DB. For more information on this, read this thread: Here is the code:
Query Non-Null Fields?
I have this table where some of the field are null. My question is: How do I query only the fields that have information? And also, how do I know from a particular row how many fields (a number) aren't empty?
Question About Null Values
A section of the documentation for the isSet() function states: Also note that a NULL byte ("") is not equivalent to the PHP NULL constant. Where would you encounter a NULL byte? Is a null byte what is returned from a field in a database?
UPDATING Null Into MySQL
I'd like to UPDATE a datetime field ONLY IF the database holds "" null already. This works using the checkbox. However, if I do not tick the checkbox, then it tries to update the datetime field in the database with "" null. This gives the error: Error: Incorrect datetime value: '' for column 'Started' at row 1 Of course it is correct, "" is not a correct datetime value. Does anyone know how I can simply get it to do nothing if the 'Started' box is not checked? Code:
Replacing NULL Values
I've written a page with some sales analysis on it and the figures are broken down in a table by month and customer. My problem is that when there are no sales in a particular month for that customer the cell of the table is blank as oppose to showing quantity = 0, value = £0 Code:
Getting Rid Of Null Values In Array
I have an array : Array ( => 10078 [9] => 10293 [10] => 10088 [11] => 10237 [12] => 10211 [13] => 10282 [14] => 10300 [15] => 10110 [16] => 10077 [19] => 10063 [21] => 10296 [22] => 10280 [23] => 10082 [27] => 10079 [29] => 10080 [30] => 10301 [31] => 10291 [32] => 10290 [33] => 10294 [34] => 10111 ) i want to be able to keep the same order of the values but i need the index to NOT skip! notice the first array is and then the next one is [9]. how can change this so the array numbers are ,[1],[2],etc.?
Array_unique Is Creating A NULL Array?
I'm writting a find and replace script for my sites internal search. Basically it is for the creation of a list of keywords that can later be fed through the search (kinda an advanced search of sorts)... Anyways, I've rewritten the function several times, and I think I am getting close, but there is one last snag. I am using array_unique() to remove the duplicates that are created by the function, and it is reutrning NULL. What's the deal? function findreplace() { extract($GLOBALS); if ($hold == 1) { return trim(stripslashes($keywords)); } $find = strtolower($_POST['find']); $replace = strtolower($_POST['replace']); $keywords = trim(strtolower($keywords)); //if ($_POST['replace_words'] == "Replace Words") { ....
Handling Null Row From Mysql Database.
I have a php script that pulls data from a mysql database that works perfectly. It pulls the ud, city, state and username from a database. In some instances, the city and state values are null and I want the script to print 'N/A' instead. What do I need to add to my script below to do that? Code:
JavaScript To Enter Date & Null
I have a PHP web page which uses a HTML form. I would like to enter dates into the date fields using a JavaScript calendar, similar to the way phpMyAdmin does. Can anyone recommend a JavaScript that will do this? Also, how can I add a button to a form to enter a NULL.
Test For The Existence Of A Null Property
I'm looking for a method to test, whether an object has a certain property. Consider the following snippet: class A { var $aaa; } $var = new A; (Assuming that the structure of class A is unknown) I need a way to check whether $var->aaa exists (test positive), and whether $var->xxx exists (test negative). I tried boolean tests, isset(), is_null(), but they can't tell the difference. I guess I could convert the object to an array and test its indices, but that wouldn't be practical for large object with many fields.
Insert NULL DateTime Field
I'm having problems inserting a NULL value into an SQL DateTime field. The Field is set to allow Null values and any other value works correctly but when I try to leave the date blank on the form it insert 01/01/1970 00:00:00 - I'm guessing its an SQL baseline. Code:
Inserting A Null Value Into Mysql Database
i have a form that submits data to a php result page. i then insert that data into a mysql database. Null values ARE allowed and the problem is when i try to insert a null number value, it errors. $ticket_number = $_POST['ticket_number']; $another_number = $_POST['another_number']; $query = "INSERT INTO ticket (ticket_number, another_number) values ($ticket_number, $another_number); mysql_query($query) or die(mysql_error()); ticket number is required, but another_number is not. error: youg have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near ')' at line 1 the ')' refers to the end of the close parenthasis in the sql statement. the thing is, in mysql i could have just done: insert into ticket (ticket_number, another_number) values (1, NULL); how do i replicate that in a php statement. the same thing happens with a null date type too. There has to be a way!
Enter NULL If Field Is Empty
I have a script where I add news to a database. I am adding a new field for an image for the respective article, but I need the script to check if there is a value for the image or not, and if there isn't, I want it to enter NULL in the DB. Code:
SELECT * FROM Table WHERE Column IS NOT NULL
I am running the following MySQL query: <?php $sql = mysql_query("SELECT * FROM comics WHERE story_arc IS NOT NULL") or die (mysql_error()); while($row = mysql_fetch_assoc($sql)) { echo $row['title']; } ?> The problem is that it is outputting all 4000+ records, when it should only be about 100. Is there an error with my 'IS NOT NULL'?
Mysql - DEFAULT '' Defined Yet NULL Inserted
My database was inserting NULL for empty strings so I changed the field definition with this query: ALTER TABLE `myTable` CHANGE `myUrl` `myUrl` VARCHAR( 255 ) NOT NULL DEFAULT '' No error was reported following the query and yet I still get NULLs on insertions.
Insert NULL Not Blank Into MySQL With PHP Script
Here's my question: How do I pass a NULL value in a variable to a MySQL DB? Here's an overview of my problem: I have a PHP page that processes code, then inserts the code into a database. Very straightforward. But, some NULL values are being inserted as a blank space, or the string "NULL" instead of a true NULL. Below is the db insert...
Catching NULL Values Returned To Mysql_fetch_array()
Does anyone know how I can catch a null value that is passed to a reference to mysql_fetch_array? For example, I have the following code (i use classes intensively, so forgive me if the code appears complicated): print ( $this->_db->row[ "date" ] ); I get the following warning: PHP Warning: Undefined index: date in c:inetpubincludephplibBulletinBoard.php on line 193 I KNOW that this is because the value in the date field is null. I want to be able to catch this and control the output if it's null. Does anyone know of a PHP specific function (or even a mySQL function) that will help me do this?
PEAR:SOAP -> NULL Values To C#-client?
I wrote a PEAR:SOAP webservice reading data out of a database and returning it in form of a struct to a C#-client. The problem is, that C# can't read NULL values for datatypes like INT, DOUBLE etc. When I use the attribut "nil=true" for an element of the struct it works fine with strings. In C# the string in the struct is also NULL. But INT, DOUBLE etc are initialized with "0" by C#. How can I return NULL values to the client? I thought about using the SqlTypes, because these are able to get the value NULL. But how can I implement these Types in my PEAR:SOAP webservice? Where do I get such a schema? Or is there any other solution for this problem?
Mysql Null Field Values Not Being Returned
is there a workaround for rows with null values not being returned? I am using PHP 4.3.2 and mysql. the mysql_fetch_array just seems to ignore some of the latest rows with null values.
Problems With $_POST Returning NULL Values In Php 4.4.2
so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL values for all posted vars. What's the deal? NOTE: when i use $_GET the script just works. script with the form: <?php // Connect to a session session_start( ); ?> <form method="POST" action="reg_validate.php"> <h2>User Profile</h2> <?php // Show meaningful instructions for UPDATE or INSERT or errors if(empty($errors)) { if (session_is_registered("loginUsername")) { echo "<p><b>Please update your profile below as needed:</b></p>"; } else { echo "<p><b>Please fill in all details below to join.</b></p>"; } }else{ // Display error message to the user showMessage(); } ?> <table> <col span="1" align="right"> <tr><td>User Name:</td> <td><? echo fieldError("userName", $errors); ?> <input type="text" name="userName" value="<? echo $formVars["userName"]; ?>" size=25></td> </tr>
Hiding Static Content If Column Is Null
I have a page that is pulling information from a database of local businesses. One of the columns is a URL and on the page I have a link 'Visit website' and the url from the database is the link. However, not all the entries in my database have a website and are null. So this is creating the problem that some of my listing have a link that says visit website, that go nowhere. This is the code i am using: <a href="<?php echo $row_Businesses['website']; ?>" target="_blank">Visit Website</a> What I would like is, if the 'website' column is null then the visit website link doesn't appear but if there is an entry for the 'website' column then there is a link saying visit website that has the 'website' column entry as the link (like above).
|