-
Posts
80 -
Joined
-
Last visited
Never
Posts posted by sandeep529
-
-
Try,
list($var1,$var2) = explode('~'," This is not I would like to do ~ what do you mean"); echo $var1; echo $var2;
-
are you looking for something like this..
http://www.phpclasses.org/browse/file/26537.html
This class I made specifically to shorten syntax for Database operations...
-
Will this work...?
This uses the class I mentioned in previous message....
$blog = array( array('name'=>'entry 1','title'=>'title 1','type'=>'misc') , array('name'=>'entry 2','title'=>'title 2','type'=>'misc2','anotherEntry'=>'entry content') ); include 'crXml.php'; $crxml = new crxml; foreach($blog as $c => $entry) { foreach($entry as $k=>$v) { $crxml->item[$c]->$k = $v; } } echo $crxml->xml();
Outputs
<?xml version="1.0" encoding="UTF-8"?> <item> <name>entry 1</name> <title>title 1</title> <type>misc</type> </item> <item> <name>entry 2</name> <title>title 2</title> <type>misc2</type> <anotherEntry>entry content</anotherEntry> </item>
Just replace the blog array with any content from your blog.....
-
Do you want to provide an rss feed to the user, or you want to use data from external RSS feeds to be displayed in your site?
RSS is basically xml so what you will need to do will be XML parsing or XML generation...you can try SimpleXML or DOM XML functions...
There is also a class I have created for xml parsing/generation/manipulation called crXml, the usage of which I have outlined in the thread
http://www.phpfreaks.com/forums/index.php?topic=351131.msg1657792#msg1657792
-
I am sorry, but the docuementation for the above class CRXML at crxml.pagodabox.com in under construction...
please refer to http://www.phpclasses.org/browse/file/34394.html for complete documentation.
Sandeep...
-
hi,
Your XML contains a bit of namespaces, So if you find simpleXML difficult, you can try using a class I created. Which makes accessing CDATA sections and namespaces easy/
You can download the archive at
http://crxml.pagodabox.com/crxml.tar
The advantage of this class is that you have a search function. You can call it with a name 'visibility' and it will return the php statement using this class that you can use to access the value of that node.
for example after loading your xml into the class , the statemment
var_dump($crxml->search('visibility'));
will output array with 1 element.
array(1) { [0]=> array(7) { ["nodeName"]=> string(10) "visibility" ["accessStatement"]=> string(85) "...->dwml->data[1]->parameters->weather->{'weather-conditions'}[1]->value->visibility" ["nodeChildrenCount"]=> int(1) ["nodeType"]=> int(1) ["namespaceURI"]=> NULL ["nodeContent"]=> string(52) "<visibility units="statute miles">10.00</visibility>" ["htmlEncodedNodeContent"]=> string(74) "<visibility units="statute miles">10.00</visibility>" } }
In the above section there is a "accessStatement" element....this contains value "->dwml->data[1]->parameters->weather->{'weather-conditions'}[1]->value->visibility"
so to access the value of that node from php you can use
echo $crxml->->dwml->data[1]->parameters->weather->{'weather-conditions'}[1]->value->visibility;
will echo 10.
to get the 'Units' attribute for visibility you can give as
echo $crxml->dwml->data[1]->parameters->weather->{'weather-conditions'}[1]->value->visibility['units']
will echo 'statute miles'...
This way you dont have to manually find your way through the XML. What ever you can do with simpleXML like iterating, You can do with this class also.
I have to warn you that even though I have somewhat tested and is activity developing this class, I am the only one working on this.
So you might want to try simplexml first. Even though it seems a bit hard to me, people have been using it for long, and there will be solutions in the net for what ever issue you come up with.
Or try using DOM XML functions. Its What I have used to make the above class. I Have found it much more consistent and powerful.
If you use DOM function, you better take a look at XPath also http://www.tizag.com/xmlTutorial/xpathtutorial.php.
If you choose to use simpleXML pls see the link
http://blog.preinheimer.com/index.php?/archives/172-SimpleXML,-Namespaces-Hair-loss.html
That is not meant to scare you. But it shows how to access xml nodes when namespaces are involved
Good Luck.....
-
-
-
You're talking about the one(s) you posted ~3 weeks ago, yah?
No, But the one I Posted ~2 days back....
-
hi,
I have started a thread with title 'Need some testing for this very Short XML beautifier in PHP' in the beta testing forum, and it is neither deleted nor approved. Please let me know what is happening?
-
-
I still don't understand why you don't like to use strtotime()? It works fine and it doesn't matter if you have preceding zeros or not
Check it, for example
var_dump( strtotime( '2012-01-05' ) < strtotime( '2012-1-4' ) );
I love strtotime()..its a great function. I was just curious if string comparision will work under any circumstances. I nevertheless always use date functions for all date/time comparisons
-
if ('2012-01-03' == '2012-1-3') {
I was actually expecting something like
var_dump('2012-01-05' > '2012-1-4');
The above statement returns false. But with preceding zeros for the second date it returns true. So that pretty much settles it...Thank you Adam...
-
I have created this short function for formatting xml strings using recursion and anonymous function. Can you guys check and tell me if it is really working...?
Also if this can be done in a shorter way?
Please avoid the xml version tags and the style sheet declarations for now, as it would break the function. I have included a sample xml in the code posted below...
<?php $xmlstr = <<<EOB <Item xmlns="http://uriofthenamespace.com" Type="Book"><Name>Freedom at Midnight</Name><Authors><Author><FirstName>Collins</FirstName><LastName>Larry</LastName></Author><Author><FirstName>Lapierre</FirstName><LastName>Dominique</LastName></Author></Authors><Price><![CDATA[150.00]]></Price></Item> EOB; function indent($str,$il=0,&$count=null) { $indentChar = " "; $str = preg_replace("#>\s*(\w|<)#",">\\1",$str); $replacer = function($str) use($il,$indentChar) { $str[3] = trim($str[3]); $count = 0; if(substr($str[3],0,9)!='<![CDATA[') $str[3] = indent($str[3],$il+1,$count); $n=$count?"":"\n$indentChar"; $str[3] = str_replace("\n","\n".str_repeat($indentChar,$il),$str[3]); return "\n{$str[1]}$n{$str[3]}\n</{$str[2]}>"; }; $return = preg_replace_callback("#(<(\w*?).*>)(.*)</\\2>#Uism",$replacer,$str,-1,$count); if($il==0) return preg_replace("#(<\w*/>)([^<]+)\n(\s*)<#Uism","\\1\n\\3$indentChar\\2\\3\n\\3<",preg_replace("#(<\w*/>)\n(\s*)(\S)#Uism","\n$indentChar\\2\\1\n\\2\\3",$return)); else return $return; } echo indent($xmlstr);
-
Yes, as long as the format is YYYY-MM-DD, it will compare directly, with one caveat: the leading zeros are NOT optional.
Yea...I thought about that..but could not find an instance where it would compare wrongly for want of leading zeros....Can you think of any?
-
Sorry... I didn't see your answer You may use, of course, strtotime() function. It converts string to UNIX time, in seconds. Then you may compare these times.
But you dont even need strtotime().It seems just plain string comarison will do if the format is YYYY-mm-dd.
-
does the domain names in the url remain same between the pages.
I mean does the www prefix change between pages?
-
Sandpeep: Thanks for the help, but Postgresql does not support Unix timestamps
As unix timestamps are just integers, you can use interget column to store a unixtimestamp....
-
-
Hi..
I would ask myself the question...
which is done often? Extending the options object or using it?
I would choose the method that will make the most often used operation simple....
-
May be you should use the miltiline modifier http://php.net/manual/en/reference.pcre.pattern.modifiers.php.
So your regex becomes
$desc_pattern = '/\<div class=\"on\">.*<p>(.*)<\/p><\/div>/sm';
-
Hi,
The procedure I am outlining here is Just my Idea. I need someone to confirm its reliability...
The best way to handle the situation would be to use Unix Timestamps. This is because unix timestamps are timezone independent.
This means when some thing is to happen at a timestamp of X, then it has to happen when X seconds have passed since 1970-01-01 00:00:00 at greenwich.
In otherwords servers running in different parts of the world running in different timezones always return the same unix timestamp.
echo date_create('2011-12-30 00:00:00 GMT')->format('U');echo "<br/>"; echo date_create('2011-12-30 05:30:00 GMT+5:30')->format('U');echo "<br/>";
So if you want a user in timezone GMT+5:30 (India) to recieve a notification at say Jan 15 2012 00:00:00, you have to find what is the unix timestamp when a clock in india shows time Jan 15 2012 00:00:00; can be done as...
$timestamp_one = date_create('2012-01-15 00:00:00 GMT+5:30')->format('U');
Insert that value in the database.
You can also insert the value of unix timestamp when a clock in GMT timezone shows Jan 15 2012 00:00:00; can be done as
$timestamp_two =gmmktime(0,0,0,1,15,2012);
This is for handling the second one in the following situtations...
For querying.
Situtation 1:
1.Your server clock shows 2012-01-15 6:24:34
2.You have a user in database with notification timestamp_one, $user_notification_timestamp = 1326607200.Assume that this timestamp is a hour boundary like 5:00:00 ...and not like 5:34:34...
3. You have to check if the user has to be notified
You have to do the following
$my_last_hour_timestamp = mktime(6,0,0,1,15,2012); //returns the unix timestamp when your server clock was at 2012-01-15 6:00:00 if($my_last_hour_timestamp == $user_notification_timestamp) send_user_notification();
Situtation 2:
1.Your want to send a notification to all users with a notification time of 2012-01-25 9:00:00/their time right now....
2.You have a user in database with notification timestamp_two ,$user_notification_timestamp_two = 1326607200.Assume that this timestamp is a hour boundary like 5:00:00 ...and not like 5:34:34...
You have to do the following
$timestamp = gmmktime(9,0,0,1,25,2012); //returns the unix timestamp when a C LOCK AT GMT is at 2012-01-25 9:00:00 if($timestamp == $user_notification_timestamp_two) send_user_notification();
I dont know if this is the best method..So You may want to wait till someone else reply....
Good Luck....
-
This http://ru.php.net/manual/en/book.datetime.php may help you.
Thanks. But I was not really looking for help on date handling in php. Just wondering if there are any cases were simple string comparison wont work....
-
Hi guys
I was just wondering if there is some date combination for which this type of comparisons will not work.
var_dump("2010-15-1">"2010-4-01");
Provided the date is always in the YYYY-mm-dd format with optional preceding 0 .
Thanks
searching a range when only high/low in database
in PHP Coding Help
Posted
I think you could join that table to itself .
If the table name is dimensions, you can use something like