php-general Digest 17 Aug 2009 05:24:10 -0000 Issue 6289
php-general Digest 17 Aug 2009 05:24:10 - Issue 6289 Topics (messages 296836 through 296865): Re: Issue with the huge import script 296836 by: Phpster Re: How do I extract link text from anchor tag as well as the URL from the href attribute 296837 by: chrysanhy 296839 by: Ralph Deffke 296840 by: Ralph Deffke 296841 by: chrysanhy 296842 by: chrysanhy 296846 by: Ralph Deffke 296847 by: Ralph Deffke 296858 by: chrysanhy Dan Brown 296838 by: Angus Mann 296844 by: Per Jessen Cannot exec in my own directory 296843 by: Dotan Cohen 296845 by: Sudheer Satyanarayana 296850 by: Dotan Cohen 296852 by: Caner Bulut 296856 by: Dotan Cohen Sanitizing mysql inserts of user data 296848 by: Dotan Cohen 296851 by: Caner Bulut 296853 by: Adam Randall 296854 by: Dotan Cohen 296855 by: Dotan Cohen brainstorm/samples on _autoload() needed 296849 by: Ralph Deffke Re: Another date exercise 296857 by: Paul M Foster 296860 by: Ralph Deffke running str_replace, it misbehaves! 296859 by: Allen McCabe link to a css file requires .css ??? 296861 by: Daniel Kolbo 296862 by: Nitsan Bin-Nun 296863 by: Daniel Kolbo 296864 by: Adam Shannon Re: File or directory? 296865 by: George Langley Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- On Aug 15, 2009, at 9:15 PM, Devendra Jadhav devendra...@gmail.com wrote: Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav What are the databases? Both mysql? Or different systems? How do you define whether the record exists? Are you running into timeout issues? If so, one trick is to write the page to process 100 or so records at a time and then use JavaScript to reload the page to avoid the timeout issues. Bastien Sent from my iPod ---End Message--- ---BeginMessage--- It did not work. Both gave me a Call to undefined method fatal error. On Sun, Aug 16, 2009 at 1:43 AM, Ralph Deffke ralph_def...@yahoo.de wrote: try $link-nodeValue() or $link-getContent() im not shure which one works on an image link which is indeed a child of a so u could also check if the node has a child, if so its an image with, in good practice. an alt attribute to use haven't tried but should work. let me know pls ralph_def...@yahoo.de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ---End Message--- ---BeginMessage--- did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links
[PHP] How do I extract link text from anchor tag as well as the URL from the href attribute
I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks
Re: [PHP] Another date exercise
tedd wrote: Hi gang: Here's another exercise to consider. This is a date entry problem where the user can enter a date in various forms, but the return will be in a consistent format. For example, a user might enter a date in the form of: August 5, 2009 Aug 05 2009 Aug 5, 9 08/05/09 8-5-9 8 05 2009 8,5,9 Or any combination thereof. However, the resultant date will be standardized to: Aug 5, 2009. Extra points for solving this for Euro as well as US date formats (i.e., 5 Aug, 2009 vs Aug 5, 2009). And, extra extra points for accommodating month brevity, such as A for August and Mar for March and so on. But the real problem here is 05/08/09 is still August 5 2009 . So teaching customers to use 2009.08.05 removes the hassle of needing to know where your target site is based! But as has been said, the real solution is a date picker. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
try $link-nodeValue() or $link-getContent() im not shure which one works on an image link which is indeed a child of a so u could also check if the node has a child, if so its an image with, in good practice. an alt attribute to use haven't tried but should work. let me know pls ralph_def...@yahoo.de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Another date exercise
On Sun, 2009-08-16 at 08:36 +0100, Lester Caine wrote: tedd wrote: Hi gang: Here's another exercise to consider. This is a date entry problem where the user can enter a date in various forms, but the return will be in a consistent format. For example, a user might enter a date in the form of: August 5, 2009 Aug 05 2009 Aug 5, 9 08/05/09 8-5-9 8 05 2009 8,5,9 Or any combination thereof. However, the resultant date will be standardized to: Aug 5, 2009. Extra points for solving this for Euro as well as US date formats (i.e., 5 Aug, 2009 vs Aug 5, 2009). And, extra extra points for accommodating month brevity, such as A for August and Mar for March and so on. But the real problem here is 05/08/09 is still August 5 2009 . So teaching customers to use 2009.08.05 removes the hassle of needing to know where your target site is based! But as has been said, the real solution is a date picker. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php Seriously, go out and beat your clients over the head, and then hit them about some more until they understand the folly of using bad date formats. US-style dates are just the start of it! Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
because I assume always that a requester got some intelligence, so in that case there must be a reasonsble reason why he wants to do it in PHP im not like u assuming everybody is a thumb ralph Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250413427.2344.51.ca...@localhost... On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
On Sun, 2009-08-16 at 11:05 +0200, Ralph Deffke wrote: because I assume always that a requester got some intelligence, so in that case there must be a reasonsble reason why he wants to do it in PHP im not like u assuming everybody is a thumb ralph Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250413427.2344.51.ca...@localhost... On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk There are rare occasions on this list where the best answer is not PHP, and I believe this is one of them. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
so then tell me tell me what my first sentence means this sounds huge, and cries for a sql version of the import. it looks like u have no experience in working as consultant hotlines Ash first the folk is asking for a sulotion of HIS php implying a general solution in PHP with a hint to the prof solution I think thats what I did Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250414284.2344.55.ca...@localhost... On Sun, 2009-08-16 at 11:05 +0200, Ralph Deffke wrote: because I assume always that a requester got some intelligence, so in that case there must be a reasonsble reason why he wants to do it in PHP im not like u assuming everybody is a thumb ralph Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250413427.2344.51.ca...@localhost... On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk There are rare occasions on this list where the best answer is not PHP, and I believe this is one of them. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
On Sun, 2009-08-16 at 11:25 +0200, Ralph Deffke wrote: so then tell me tell me what my first sentence means this sounds huge, and cries for a sql version of the import. it looks like u have no experience in working as consultant hotlines Ash first the folk is asking for a sulotion of HIS php implying a general solution in PHP with a hint to the prof solution I think thats what I did Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250414284.2344.55.ca...@localhost... On Sun, 2009-08-16 at 11:05 +0200, Ralph Deffke wrote: because I assume always that a requester got some intelligence, so in that case there must be a reasonsble reason why he wants to do it in PHP im not like u assuming everybody is a thumb ralph Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250413427.2344.51.ca...@localhost... On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk There are rare occasions on this list where the best answer is not PHP, and I believe this is one of them. Thanks, Ash http://www.ashleysheridan.co.uk You did say this cries for a pure SQL solution, which you then went on to say involved PHP. Call me a pedant, but PHP is not SQL. And please, try to leave insults out of the list in future, it makes you look unprofessional. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Issue with the huge import script
On Sun, 16 Aug 2009 04:15:12 +0300, Devendra Jadhav devendra...@gmail.com wrote: Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D What about using insert ignore ? :) 1. add UNIQUE constraint on a key you want to add, so you won't be able to add row with same ID twice. 2. then use INSERT IGNORE into = easy to code, easy to use. Of course, this aproach won't work if database will grow larger and larger. (if you adding new rows all the time) Then it is better to use this aproach: 1. add auto_increment column to original table. 2. before getting new rows from old table, check what is maximum ID from new table. 3. get only rows where old_table.id new_table.max_id remember to ORDER BY ID ASC. -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Issue with the huge import script
better consider if u r insulting I've seen a view posts of u falling into that category i w'ld recomment respect posters first approaches even if they r stupid and incorporate the respect in the way u answer the comment you r crying ... is an insult. Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250417781.2344.58.ca...@localhost... On Sun, 2009-08-16 at 11:25 +0200, Ralph Deffke wrote: so then tell me tell me what my first sentence means this sounds huge, and cries for a sql version of the import. it looks like u have no experience in working as consultant hotlines Ash first the folk is asking for a sulotion of HIS php implying a general solution in PHP with a hint to the prof solution I think thats what I did Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250414284.2344.55.ca...@localhost... On Sun, 2009-08-16 at 11:05 +0200, Ralph Deffke wrote: because I assume always that a requester got some intelligence, so in that case there must be a reasonsble reason why he wants to do it in PHP im not like u assuming everybody is a thumb ralph Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1250413427.2344.51.ca...@localhost... On Sun, 2009-08-16 at 04:06 +0200, Ralph Deffke wrote: Hi, this sounds huge, and cries for a sql version of the import. Are both databases the same? MySQL? I give u a draft for MySQL u export the data u have, then u got a textfile with 10+ sql statments in the php script u open the file and iterate over it by line (carefull it could be also ; in case its a Unix created file on a windows platform) line == one SQL insert in table bla bla... in the loop then just mysq_query with this line if the the someid is an unique index the insert will fail, so only those records are inserted beeing not already in the database. but I think as of the amount off records it doesn't sound like a every 10 minutes job, if it is a rara job, just do it with phpMyAdmin sorry not pulling out the code, but was a long day behind the keyboard, need some sleep ralph_def...@yahoo.de Devendra Jadhav devendra...@gmail.com wrote in message news:be4b00cf0908151815r1c7430d2j8a6cb0da1f10a...@mail.gmail.com... Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav You cry for a MySQL version and then revert back to PHP?! Why not just keep the whole thing in MySQL? You can use SQL statements to check whether a record exists before attempting to shove it in the database using a WHERE clause in the INSERT statement or by making one field unique and hiding notices about inserts that are attempting to overwrite that. Thanks, Ash http://www.ashleysheridan.co.uk There are rare occasions on this list where the best answer is not PHP, and I believe this is one of them. Thanks, Ash http://www.ashleysheridan.co.uk You did say this cries for a pure SQL solution, which you then went on to say involved PHP. Call me a pedant, but PHP is not SQL. And please, try to leave insults out of the list in future, it makes you look unprofessional. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Issue with the huge import script
On Aug 15, 2009, at 9:15 PM, Devendra Jadhav devendra...@gmail.com wrote: Hi, I have to import data from one database to another, I have to import around 10(1Lac) records. First I need to check if the record is already imported or not and import only those records which are not imported. Here is my logic $already_imported = get_already_imported_records(); format of the $already_imported is $already_imported[someid] = 'imported'; Now i take all records from another db and iterating through it. if (!key_exists($already_imported[$new_id])){ import_function($new_id) }else{ echo 'allready imported'.$already_imported[$new_id]; } Now my script is importing same records for more than one time. I am not able to get through this issue Is it because of the size of the records or something else...? Please suggest me some solution which is faster, safe and easy to code :D Thanks in advance -- Devendra Jadhav What are the databases? Both mysql? Or different systems? How do you define whether the record exists? Are you running into timeout issues? If so, one trick is to write the page to process 100 or so records at a time and then use JavaScript to reload the page to avoid the timeout issues. Bastien Sent from my iPod -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
It did not work. Both gave me a Call to undefined method fatal error. On Sun, Aug 16, 2009 at 1:43 AM, Ralph Deffke ralph_def...@yahoo.de wrote: try $link-nodeValue() or $link-getContent() im not shure which one works on an image link which is indeed a child of a so u could also check if the node has a child, if so its an image with, in good practice. an alt attribute to use haven't tried but should work. let me know pls ralph_def...@yahoo.de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Dan Brown
Dan Brown is a frequent poster here and developer on the PHP team. Dan has not posted to the PHP list for quite a while and is not responding to my emails directly to him. Does anyone know if he's OK? If anyone has knowledge can they please reply to me directly - off list. Thanks, Angus
[PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
WHile waiting for suggestions for extracting the link text from the DOM, I tried a brute force approach using the URLs I had found with getAttribute(), but found myself baffled by my results. I boiled down my issue with this approach to the following snippet. $htmldata =EOB http://www.protools.com/users/user_story.cfm?story_id=1162amp;lang=1;quot;Creating Surround Mixes with Tim Weidner/aquot; img height=11 src=new.gif width=28 - iMagnification/i engineer talks about mixing the album at the iProTools/i site, by Jim Batchco http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html;quot;Don't Goquot; Video/aa href= http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html;/a img height=11 src=new.gif width=28 - Presented by Beyond Music (a href=http://www.apple.com/quicktime/download/;QuickTime/a Required) EOB; $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html'; $posn = strpos($url, $htmldata); echo URL |$url| position is |$posn|; Running this gives me: URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is || I've tried lots of functions, and even regular expressions, but I cannot get the code to find the URL in the HTML. While I still hope for a DOM solution to getting this link text, WHY can't the code find the URL in the HTML snippet? On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy phpli...@hyphusonline.comwrote: I pasted the code exactly as you have it, and I got the following: *Fatal error*: Call to undefined method DOMElement::getContent() I got the same thing with nodeValue(). On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke ralph_def...@yahoo.dewrote: did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Cannot exec in my own directory
I have a script in /home/username/script.sh with permissions 777. I can SSH into the server and execute ./script.sh to run the script, but calling it from exec in PHP does not run it. What should I start checking? Thanks. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Dan Brown
Angus Mann wrote: Dan Brown is a frequent poster here and developer on the PHP team. Dan has not posted to the PHP list for quite a while and is not responding to my emails directly to him. Does anyone know if he's OK? If anyone has knowledge can they please reply to me directly - off list. Thanks, Take a look at Dans posting from 3 August. -- Per Jessen, Zürich (28.4°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot exec in my own directory
Dotan Cohen wrote: I have a script in /home/username/script.sh with permissions 777. I can SSH into the server and execute ./script.sh to run the script, but calling it from exec in PHP does not run it. What should I start checking? Thanks. Check the include path. Try using the complete path to the file. And make sure the user PHP is running has read permissions to the directories upwards the hierarchy. -- With warm regards, Sudheer. S Business: http://binaryvibes.co.in, Tech stuff: http://techchorus.net, Personal: http://sudheer.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
well the immage goes inside the a.. img... /a on ur html the node a has no value however u should not get a error this is pergect jtml link a href=thema.htmimg src=button4.jpg width=160 height=34 border=0 alt=THEMA/a ralph chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160943t2254137fve43771c7e4f8c...@mail.gmail.com... WHile waiting for suggestions for extracting the link text from the DOM, I tried a brute force approach using the URLs I had found with getAttribute(), but found myself baffled by my results. I boiled down my issue with this approach to the following snippet. $htmldata =EOB http://www.protools.com/users/user_story.cfm?story_id=1162amp;lang=1;quot;Creating Surround Mixes with Tim Weidner/aquot; img height=11 src=new.gif width=28 - iMagnification/i engineer talks about mixing the album at the iProTools/i site, by Jim Batchco http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html;quot;Don't Goquot; Video/aa href= http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html;/a img height=11 src=new.gif width=28 - Presented by Beyond Music (a href=http://www.apple.com/quicktime/download/;QuickTime/a Required) EOB; $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html'; $posn = strpos($url, $htmldata); echo URL |$url| position is |$posn|; Running this gives me: URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is || I've tried lots of functions, and even regular expressions, but I cannot get the code to find the URL in the HTML. While I still hope for a DOM solution to getting this link text, WHY can't the code find the URL in the HTML snippet? On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy phpli...@hyphusonline.comwrote: I pasted the code exactly as you have it, and I got the following: *Fatal error*: Call to undefined method DOMElement::getContent() I got the same thing with nodeValue(). On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke ralph_def...@yahoo.dewrote: did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
this worked here: ?php $html = new DOMDocument(); $html-loadHtmlFile(testHtml.html); $links = $html-getElementsByTagName('a'); echo pre; foreach ($links as $item) { echo $item-getAttribute( 'href' ). \n; echo --- . $item-nodeValue . \n; } echo /pre; ? Im sending u the 2 files directly in a minute. it came out, as I thought earlier that u have to check if the a tags has got children to extract image links. ralph_def...@yahoo.de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160943t2254137fve43771c7e4f8c...@mail.gmail.com... WHile waiting for suggestions for extracting the link text from the DOM, I tried a brute force approach using the URLs I had found with getAttribute(), but found myself baffled by my results. I boiled down my issue with this approach to the following snippet. $htmldata =EOB http://www.protools.com/users/user_story.cfm?story_id=1162amp;lang=1;quot;Creating Surround Mixes with Tim Weidner/aquot; img height=11 src=new.gif width=28 - iMagnification/i engineer talks about mixing the album at the iProTools/i site, by Jim Batchco http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html;quot;Don't Goquot; Video/aa href= http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html;/a img height=11 src=new.gif width=28 - Presented by Beyond Music (a href=http://www.apple.com/quicktime/download/;QuickTime/a Required) EOB; $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html'; $posn = strpos($url, $htmldata); echo URL |$url| position is |$posn|; Running this gives me: URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html| position is || I've tried lots of functions, and even regular expressions, but I cannot get the code to find the URL in the HTML. While I still hope for a DOM solution to getting this link text, WHY can't the code find the URL in the HTML snippet? On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy phpli...@hyphusonline.comwrote: I pasted the code exactly as you have it, and I got the following: *Fatal error*: Call to undefined method DOMElement::getContent() I got the same thing with nodeValue(). On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke ralph_def...@yahoo.dewrote: did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Sanitizing mysql inserts of user data
I am sanitizing user-entered data before storing in mysql with this function: function clean_mysql ($dirty) { $dirty=trim($dirty); $dirty=str_replace (--, , $dirty); $dirty=str_replace (;, , $dirty); $clean=mysql_real_escape_string($dirty); return $clean; } Is this good enough to prevent SQL injection attacks? Should I add anything else? Thanks! Dotan Cohen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] brainstorm/samples on _autoload() needed
anybody out there with a ultimate solution, speed optimzed? im going now for an ultimate solution, this repeating problem sucks ralph_def...@yahoo.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot exec in my own directory
Check the include path. Try using the complete path to the file. And make sure the user PHP is running has read permissions to the directories upwards the hierarchy. Thanks. I am using the complete path to the script: exec(/home/username/script.sh); In the /home/username/ directory there are other files, such as database_connection.inc that I regularly include_once in my PHP scripts, so I know that PHP has read access to that directory. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Sanitizing mysql inserts of user data
Hi Dotan, You can use htmlentities(), htmlspecialchars() and strip_tags() functions when you show your saved data on your web pages. mysql_real_escape_string function saved data into mysql DB with a secure way. But when you try to show data you still have to control it. Thanks. Caner. -Original Message- From: Dotan Cohen [mailto:dotanco...@gmail.com] Sent: Sunday, August 16, 2009 9:43 PM To: php-general. Subject: [PHP] Sanitizing mysql inserts of user data I am sanitizing user-entered data before storing in mysql with this function: function clean_mysql ($dirty) { $dirty=trim($dirty); $dirty=str_replace (--, , $dirty); $dirty=str_replace (;, , $dirty); $clean=mysql_real_escape_string($dirty); return $clean; } Is this good enough to prevent SQL injection attacks? Should I add anything else? Thanks! Dotan Cohen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Cannot exec in my own directory
Dotan, Please copy your script in the Linux include paths. Such as /usr/local/bin and give it neccecary permission and try your script again. If you still have any problem, we understand that it is no related script path problem and permissions. Maybe there is some problems on your php script. Thanks -Original Message- From: Dotan Cohen [mailto:dotanco...@gmail.com] Sent: Sunday, August 16, 2009 9:46 PM To: Sudheer Satyanarayana Cc: php-general. Subject: Re: [PHP] Cannot exec in my own directory Check the include path. Try using the complete path to the file. And make sure the user PHP is running has read permissions to the directories upwards the hierarchy. Thanks. I am using the complete path to the script: exec(/home/username/script.sh); In the /home/username/ directory there are other files, such as database_connection.inc that I regularly include_once in my PHP scripts, so I know that PHP has read access to that directory. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sanitizing mysql inserts of user data
What you are doing here is potentially altering valid user information coming into MySQL. For example, if someone legitimately enters in -- or ; into some string that is going to be put into MySQL, some comment or such, then what is put in, and then put out if you display it, won't be the same. You should in pretty much all cases be safe with just using the mysql_real_escape_string, which takes care of the - for you as well. Adam. On Sun, Aug 16, 2009 at 11:42 AM, Dotan Cohendotanco...@gmail.com wrote: I am sanitizing user-entered data before storing in mysql with this function: function clean_mysql ($dirty) { $dirty=trim($dirty); $dirty=str_replace (--, , $dirty); $dirty=str_replace (;, , $dirty); $clean=mysql_real_escape_string($dirty); return $clean; } Is this good enough to prevent SQL injection attacks? Should I add anything else? Thanks! Dotan Cohen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Adam Randall http://www.xaren.net AIM: blitz574 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sanitizing mysql inserts of user data
You should in pretty much all cases be safe with just using the mysql_real_escape_string, which takes care of the - for you as well. If I remember correctly, TFM once stated that mysql_real_escape_string does not prevent SQL injection attacks, though I am hard pressed to think of what it _is_ for, then. I now see that the manual has this note: Note: If this function is not used to escape data, the query is vulnerable to SQL Injection Attacks. Does that necessarily imply this: If this function is used to escape data, the query is not vulnerable to SQL Injection Attacks.? Logically, it does _not_ mean the same thing. -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sanitizing mysql inserts of user data
2009/8/16 Caner Bulut caner...@gmail.com: Hi Dotan, You can use htmlentities(), htmlspecialchars() and strip_tags() functions when you show your saved data on your web pages. mysql_real_escape_string function saved data into mysql DB with a secure way. But when you try to show data you still have to control it. Thank you Caner. This is the function that I use to escape HTML after it has been pulled out of the database: function clean_html ($dirty, $noNewlines=0) { $dirty = strip_tags($dirty); $dirty = str_replace(\r\n, \n, $dirty); $dirty = str_replace(\r, \n, $dirty); if ($noNewlines==1) { $dirty = str_replace(\n, , $dirty); } $dirty = ereg_replace( ' +', ' ', $dirty); $dirty=trim($dirty); $dirty = str_replace(amp;, , $dirty); $dirty = str_replace(, amp;, $dirty); $clean=htmlentities($dirty); return $clean; } It is rather convoluted but straightforward in my opinion. In addition to preventing XSS attacks, it converts newlines to *nix-style and limits them to just two newlines in a row (or none, depending on application). It also limits spaces to a single space and ensures that all ampersands are escaped properly before sanitation with htmlentities. Dotan Cohen -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cannot exec in my own directory
Please copy your script in the Linux include paths. Such as /usr/local/bin and give it neccecary permission and try your script again. I do not have root access on this machine. That is why I run the script from /home/username/ -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Another date exercise
On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote: tedd wrote: Hi gang: Here's another exercise to consider. This is a date entry problem where the user can enter a date in various forms, but the return will be in a consistent format. For example, a user might enter a date in the form of: August 5, 2009 Aug 05 2009 Aug 5, 9 08/05/09 8-5-9 8 05 2009 8,5,9 Or any combination thereof. However, the resultant date will be standardized to: Aug 5, 2009. Extra points for solving this for Euro as well as US date formats (i.e., 5 Aug, 2009 vs Aug 5, 2009). And, extra extra points for accommodating month brevity, such as A for August and Mar for March and so on. But the real problem here is 05/08/09 is still August 5 2009 . So teaching customers to use 2009.08.05 removes the hassle of needing to know where your target site is based! But as has been said, the real solution is a date picker. I *hate* date pickers. They slow down input. I can type 082309Enter faster than I can ever do it with a date picker. The date class knows I'm in America and since it's a six-digit date, it must be mmddyy. (Yes, for those of you *not* in America, I agree our dates are goofy. I think we all ought to be on the metic system, too, but America and the UK seem intent on sticking to Imperial measure.) Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: How do I extract link text from anchor tag as well as the URL from the href attribute
The code snippet below worked! Thank you so much for your time helping me with this! On Sun, Aug 16, 2009 at 11:26 AM, Ralph Deffke ralph_def...@yahoo.dewrote: this worked here: ?php $html = new DOMDocument(); $html-loadHtmlFile(testHtml.html); $links = $html-getElementsByTagName('a'); echo pre; foreach ($links as $item) { echo $item-getAttribute( 'href' ). \n; echo --- . $item-nodeValue . \n; } echo /pre; ? Im sending u the 2 files directly in a minute. it came out, as I thought earlier that u have to check if the a tags has got children to extract image links. ralph_def...@yahoo.de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160943t2254137fve43771c7e4f8c...@mail.gmail.com... WHile waiting for suggestions for extracting the link text from the DOM, I tried a brute force approach using the URLs I had found with getAttribute(), but found myself baffled by my results. I boiled down my issue with this approach to the following snippet. $htmldata =EOB http://www.protools.com/users/user_story.cfm?story_id=1162amp;lang=1 quot;Creating Surround Mixes with Tim Weidner/aquot; img height=11 src=new.gif width=28 - iMagnification/i engineer talks about mixing the album at the iProTools/i site, by Jim Batchco http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html;quot;Don't Goquot; Video/aa href= http://fi.soneraplaza.net/kaista/musiq/kaistatv/0,8883,201392,00.html /a img height=11 src=new.gif width=28 - Presented by Beyond Music (a href=http://www.apple.com/quicktime/download/;QuickTime/a Required) EOB; $url = 'http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html'; $posn = strpos($url, $htmldata); echo URL |$url| position is |$posn|; Running this gives me: URL |http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html|http://www.beyondmusic.com/MediaPlayer/Yes/DontGo.html%7Cposition is || I've tried lots of functions, and even regular expressions, but I cannot get the code to find the URL in the HTML. While I still hope for a DOM solution to getting this link text, WHY can't the code find the URL in the HTML snippet? On Sun, Aug 16, 2009 at 9:29 AM, chrysanhy phpli...@hyphusonline.comwrote: I pasted the code exactly as you have it, and I got the following: *Fatal error*: Call to undefined method DOMElement::getContent() I got the same thing with nodeValue(). On Sun, Aug 16, 2009 at 7:35 AM, Ralph Deffke ralph_def...@yahoo.dewrote: did u try it something like this foreach ($links as $link) { $int_url_list[$i][href] = $link-getAttribute( 'href' ); $int_url_list[$i++][linkText] = $link-getContent( ); // nodeValue(); } that should work send ur code then please ralph_def...@yahoo,de chrysanhy phpli...@hyphusonline.com wrote in message news:88827b190908160033n226b370bqe2ab70732811...@mail.gmail.com... I have the following code to extract the URLs from the anchor tags of an HTML page: $html = new DOMDocument(); $htmlpage-loadHtmlFile($location); $xpath = new DOMXPath($htmlpage); $links = $xpath-query( '//a' ); foreach ($links as $link) { $int_url_list[$i++] = $link-getAttribute( 'href' ) . \n; } If I have a link a href=http://X.com;/a, how do I extract the corresponding which is displayed to the user as the text of the link (if it's an image tag, I would like a DOMElement for that). Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] running str_replace, it misbehaves!
Hi friends, I'm trying to get an encrypting program working to possibly use for password insertion into a db. I set up a function that runs str_replace on a string (user supplied) two times. It searches for a single letter or number, and replace it with a pair. The next str_replace searches that new string for different pairs, and replaces them with a three-character string (symbol, character, character). I'm using % as my symbol, so I'm pretty sure this isn't the issue. It encodes, but the resulting string is way longer than expected! I set sup a decode function, with the same str_replace values, just with the replaces flipped. This works to return to me my original value, but I have to decode about 6 times (after encoding once). Basically, running a string through the encoding function will decode back to its original value, but I have to run it through the decode function multiple times to do so. Here is an example of my code: [code] ?php //ENCRYPT FUNCTIONS function format_string($string,$functions) { $funcs = explode(,,$functions); foreach ($funcs as $func) { if (function_exists($func)) $string = $func($string); } return $string; } function enc_string($string) { $search = array(a,b,c,d,e,f,g,h,i,..); //62 values $replace = array(j9,k8,q7,v6,...); //62 values $string = str_replace($search, $replace, $string); $search2 = array(9k,8q,7v,6w,5x,4y,3z,2j,); // 126 values $string = str_replace($search2, $replace2, $string); return $string; } function scrub($input) { $string = format_string($input,strip_tags,trim); $string = enc_string($string); return $string; } if(isset($_POST['input'])) { $input = $_POST['input']; $enc_password = scrub($input); } //DECRYPT FUNCTIONS function format_string2($string2,$functions) { $funcs = explode(,,$functions); foreach ($funcs as $func) { if (function_exists($func)) $string2 = $func($string2); } return $string2; } function dec_string($string2) { $search3 = array(%A1,%B2,%C3,); // 126 values $replace3 = array(9k,8q,7v,...); //126 values $string2 = str_replace($search3, $replace3, $string2); $search4 = array(j9,k8,q7,..); //62 values $replace4 = array(a,b,c,...); //62 values $string2 = str_replace($search4, $replace4, $string2); return $string2; } function scrub_set2($input2) { $string2 = format_string2($input2,strip_tags,trim); $string2 = dec_string($string2); return $string2; } if(isset($_POST['input2'])) { $input2 = $_POST['input2']; $dec_password = scrub_set2($input2); } ? body form (posts to itself) input type=text name=input id=input value=?php if(isset($input)) echo $input; ? / input type=text name=output id=output value=?php if(isset($enc_password)) echo $enc_password; ? ?php if(!isset($enc_password)) echo readonly='readonly'; ? / input type=submit name=submit value=Encrypt / [/code] I have a feeling that php is running the functions through the str_replace functions multiple times. It doesn't seem to mess with the unique-ness I had to build into it (in order to preserve the string for decoding), but it makes me nervous if it runs it through multiple times. Does anyone know why the encoding step results in such a long string? And why do I have to run decode on the result so many times to change it back? Any and all help would be greatly appreciated!
Re: [PHP] Another date exercise
i agree on date pickers and js is well use individual fields for day month and year, make month and year as drop down and u have no problem at all make live easier ralph Paul M Foster pa...@quillandmouse.com wrote in message news:20090816202217.gs2...@quillandmouse.com... On Sun, Aug 16, 2009 at 08:36:17AM +0100, Lester Caine wrote: tedd wrote: Hi gang: Here's another exercise to consider. This is a date entry problem where the user can enter a date in various forms, but the return will be in a consistent format. For example, a user might enter a date in the form of: August 5, 2009 Aug 05 2009 Aug 5, 9 08/05/09 8-5-9 8 05 2009 8,5,9 Or any combination thereof. However, the resultant date will be standardized to: Aug 5, 2009. Extra points for solving this for Euro as well as US date formats (i.e., 5 Aug, 2009 vs Aug 5, 2009). And, extra extra points for accommodating month brevity, such as A for August and Mar for March and so on. But the real problem here is 05/08/09 is still August 5 2009 . So teaching customers to use 2009.08.05 removes the hassle of needing to know where your target site is based! But as has been said, the real solution is a date picker. I *hate* date pickers. They slow down input. I can type 082309Enter faster than I can ever do it with a date picker. The date class knows I'm in America and since it's a six-digit date, it must be mmddyy. (Yes, for those of you *not* in America, I agree our dates are goofy. I think we all ought to be on the metic system, too, but America and the UK seem intent on sticking to Imperial measure.) Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] link to a css file requires .css ???
Hello, I realize this is more of an html question than a php, but I was hoping someone here would know what's going on. I am linking to a stylesheet and it is requiring me to use *.css extension. I want to use a .php extension (and have the php engine generate css). However, whenever i use a .php extension the link tag does not seem to work. This works! link rel=stylesheet type=text/css href=http://localhost:8080/some.css; / This doesn't work but I don't understand why not??? link rel=stylesheet type=text/css href=http://localhost:8080/some.php; / The page http://localhost:8080/some.php displays the css exactly the same as http://localhost:8080/some.css Why can't I link to a css file by using a different extension? Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] link to a css file requires .css ???
Of course not, just send the corresponding mime type to the file extension .css Probably header('Content-Type: text/css'); Good luck ;) On Sun, Aug 16, 2009 at 11:37 PM, Daniel Kolbo kolb0...@umn.edu wrote: Hello, I realize this is more of an html question than a php, but I was hoping someone here would know what's going on. I am linking to a stylesheet and it is requiring me to use *.css extension. I want to use a .php extension (and have the php engine generate css). However, whenever i use a .php extension the link tag does not seem to work. This works! link rel=stylesheet type=text/css href=http://localhost:8080/some.css; / This doesn't work but I don't understand why not??? link rel=stylesheet type=text/css href=http://localhost:8080/some.php; / The page http://localhost:8080/some.php displays the css exactly the same as http://localhost:8080/some.css Why can't I link to a css file by using a different extension? Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] link to a css file requires .css ???
Daniel Kolbo wrote: Hello, I realize this is more of an html question than a php, but I was hoping someone here would know what's going on. I am linking to a stylesheet and it is requiring me to use *.css extension. I want to use a .php extension (and have the php engine generate css). However, whenever i use a .php extension the link tag does not seem to work. This works! link rel=stylesheet type=text/css href=http://localhost:8080/some.css; / This doesn't work but I don't understand why not??? link rel=stylesheet type=text/css href=http://localhost:8080/some.php; / The page http://localhost:8080/some.php displays the css exactly the same as http://localhost:8080/some.css Why can't I link to a css file by using a different extension? Thanks in advance, dK ` Sorry, I am pretty sure i figured out why. I think it has to do with Content-Type header. Thanks, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] link to a css file requires .css ???
On Sun, Aug 16, 2009 at 4:37 PM, Daniel Kolbo kolb0...@umn.edu wrote: Hello, I realize this is more of an html question than a php, but I was hoping someone here would know what's going on. I am linking to a stylesheet and it is requiring me to use *.css extension. I want to use a .php extension (and have the php engine generate css). However, whenever i use a .php extension the link tag does not seem to work. This works! link rel=stylesheet type=text/css href=http://localhost:8080/some.css; / This doesn't work but I don't understand why not??? link rel=stylesheet type=text/css href=http://localhost:8080/some.php; / The page http://localhost:8080/some.php displays the css exactly the same as http://localhost:8080/some.css Why can't I link to a css file by using a different extension? Thanks in advance, dK ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Oh, I think it's part of the spec. You could always use .htaccess rules to parse .css files as .php, this will keep search engines happy and browsers happy as well. -- - Adam Shannon ( http://ashannon.us )
Re: [PHP] Re: File or directory?
is_dir() http://ca3.php.net/is_dir is_file() http://ca3.php.net/manual/en/function.is-file.php George Langley On 15-Aug-09, at 5:45 PM, Clancy wrote: On Sat, 15 Aug 2009 10:33:07 +0100, a...@ashleysheridan.co.uk (Ashley Sheridan) wrote: On Sat, 2009-08-15 at 09:56 +0200, Ralph Deffke wrote: can u upload ur own files ? can u create a directory ? Yes. are u using a ftp client ? No; I'm using straight PHP FTP Clancy clanc...@cybec.com.au wrote in message news:kjhc85hpub7drihgappifphcboolt9u...@4ax.com... I have just got access to a new server, and am playing with upload/download procedures. I looked in the root directory, and see several objects which I assume to be directories. However I was surprised to find there does not appear to be any command to determine if an object is a file or directory, either in PHP FTP or plain FTP. I could try to change to them, or download them, but this seems overkill. Am I overlooking something obvious? That answer doesn't seem to quite come close even to answering the op question. Have you looked at ftp_rawlist which returns a detailed list of files, along with their permissions and directory flags? Or you could use ftp_size to determine the size of a file, which should be nothing for a directory. Thanks, Yes; I found ftp_rawlist eventually, but I still haven't found a definition of the return code, though I think I know most of it. I guess that even a null file will hve some length? I will probably use the leading 'd' in the return code to test for directories.. (And I spent a long time trying to work out how 'drwxr-xr-x 2 riordan riordan 512 Jul 31 06:40 cgi-bin' could contain lots of spaces, before I remembered that, as a result of one of the weirder design decisions, HTML suppresses trailing spaces.) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php