etrader
-
Posts
315 -
Joined
-
Last visited
Never
Posts posted by etrader
-
-
I have a folder containing files. I want to replace some characters in the file names (e.g. "_" with "-"), then make a list of new files (renamed ones).
Thanks
-
I have a list generated from an array by foreach as
foreach ($list_array as $item) { echo "$item<br />"; }
This is a long list, how can I separate the list to different pages? I mean the simplest way to do so
-
Linked image in html has the form of
<a href="http://site.com/link.html"><img class="not important" src='imagelink.jpg' title="not important" alt="not important"/></a>
How to write href and src into an array during a foreach?
-
Nice idea, but I got an error
PHP Parse error: syntax error, unexpected '(' in the preg_match_all line
-
It is easy to get image or link by DomDocument, but I did not find a way to get image with its target link. Imagine a html as
<div class=image> <a href='http://site.com'><img src='imagelink.jpg'></a> </div>
How to get both the image link and href?
$dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $hrefs = $xpath->evaluate("/html/body//div[@class='image']"); for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i);
Now to get the image and its href, we need first getElementsByTagName('a') and getElementsByTagName('img') but they do not work inside foreach.
What's your idea?
-
Thanks for your informative reply. One more question. Does the order has an influence on cURL processing? I mean changing the order of lines in
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'); curl_setopt($ch, CURLOPT_URL,"http://www.site.com"); curl_setopt($ch, CURLOPT_FAILONERROR, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com/bot.html'); curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_TIMEOUT, 10);
-
When making a fake identity in cURL, we use
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
but which is better for the referrer:
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
or
curl_setopt ($ch, CURLOPT_REFERER, "http://www.google.com/bot.html");
-
Imagine an html with the following structure
<div class="item"> <div class="title"> <a class="title" href="http://www.domain.com/title.html">Title is here</a> </div> <div class="image"> <a href="http://www.domain.com/title.html"><img src=image.jpg /></a> </div> </div>
How to make an array containing $title - $url - $image_url ?
-
download the file first?
(untested)
$cachepage = "cache/pagename.html"; $external = "http://google.com"; if(!file_exists($cachepage)) { $ch = curl_init($external); $fp = fopen($cachepage,'w'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); curl_close($ch); fclose($fp); } $html = file_get_html($cachepage); unset($cachepage);
The only problem I have is that it writes pagename.html with chmod 644, and then unset cannot delete it or re-writing in the next run.
-
The interesting point about simple_html_dom is the ability to capture links from a webpage as
foreach($html->find('a') as $element) { $string = $element->href; }
Is it possible to do so without simple_html_dom?
-
Just throwing it out there, but maybe using one of the half dozen built-in DOM libraries in PHP instead of one thrown together with a bunch of regular expressions and recursive calls would improve performance?
What do you mean by that? I did not get it
-
This will write "http://google.com" on pagename.html in cache directory?
I must create this file to be written ?
-
I successfully load a page by simple_html_dom.php (developed in simplehtmldom.sourceforge.net) as
$html = file_get_html('externalpage');
But sometimes this make a high load on CPU and the page does not load for a long time (probably due to the external site server). How can I skip the process when it is not normal to avoid high CPU usage?
-
Perfect solution! Thanks!
-
I have a foreach loop as
foreach ($xml->channel->item as $value){ $title = $value->title; $text = $value->text; echo "$title <br /> $text"; }
I want to skip any entry in which the title contains a character like ":"
-
I have two xml files as
$xml1 = simplexml_load_file("1.xml"); $xml2 = simplexml_load_file("2.xml");
and want to merge them to create an array for a foreach process.
-
I have some similar arrays. How I can combine them to shuffle the new array?
-
Sorry for that. I thought that RFC 822 can have four-digit year.
I think DATE_RFC2822 or DATE_RFC1123 suits my need
-
I prefer to have four-digit year as Mon, 15 Aug 2005 15:52:01 +0000
-
Yes! As I run the above-mentioned code, it produces Mon, 15 Aug 05 15:52:01 +0000
-
sounds good , but it shows two-digit year instead of four-digit: 11 instead of 2011.
-
How to change the date in format of ISO-8601 (example: 2005-08-15T15:52:01+0000) to RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)?
-
Actually, I loved the option1. It was so brilliant. Thanks a million
-
It is a variable string. It is not a static text. It comes from a dynamic array.
Renaming files in a folder and make a list
in PHP Coding Help
Posted
My issue is about renaming. How in a php script I can command to re-write files in a folder?