Jump to content

AHA7

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

AHA7's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, Say, that I have an HTML page with many tables and with each table has a unique class (styling) for its rows that is different from other tables'. I use the dom class (DomDocument()) to load the HTML page for other purposes but it would be nice if I could achieve this using dom functions as follows: I want to get the attribute class (its value) of the first, and only the first, childnode (<tr>) of each table on the page. Note: each <tr> element in all tables has its own class attribute with unique value to each table. All the rows (<tr>'s) of the same table has the same value for their class attribute. How can I do that?
  2. I did read the mannual, but they didn't specifically say anything about what curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, VALUE) returns when the connection times out. I have also tried to do some tests but the connection seemed to always succeed. Could not make it time out.
  3. Hello, I have a few questions about cURL, please! 1- I want to use cURL in a loop to open a few documents. Do I have to put the two functions curl_init() and curl_close() inside the loop or I can put them outside. Notice that in each iteration of the loop a different document is opened. Example, is the following correct: $ch = curl_init(); //This is outside the loop for($i=1; $i <= $filecount; $i++) { $path = ${'file_location_' . $i}; curl_setopt($ch, CURLOPT_URL, $path); //The handle $ch was set outside the loop. . . . curl_exec($ch); } curl_close($ch); //This is outside the loop 2- In the loop above if CURLOPT_CONNECTTIMEOUT was set to 5 (timeout after 5 seconds), and say in the third iteration of the loop the connection times out and it fails to connect to the site, then what would happen? Would other curl_setopt() functions and the function curl_exec() be executed or not? 3- What does the function curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5) return when the connection times out and it fails to connect to resource? Can I use the returned value to display a customized error message when the connection times out?
  4. Hello, I want to search a string for a .com URL which may contain a trailing slash. If it does contain a trailing slash I want to strip it out using preg_replace. If it doesn't contain a trailing slash then I want to keep it as is and in both cases I want to store the no-trailing-slash-URL in the variable $URL_with_trailing_slash_stripped. (I do not want to affect the original string). Here's my solution: preg_match('/http://.*\.com[/]?/', $string, $matches); $URL_with_trailing_slash_stripped = preg_replace('//$/', '', $matches[0]); And here are my two questions: 1- Is the second line of the code above valid? Does preg_replace return a string and so I can store it in a variable? If not, how can I convert it to a string and store it in a variable? 2- Do I have to wrap the regex with forward slashes '//$/' (I have seen people do so and I don't know why)?
  5. Hello, I am struggling with a regex format and I am starting to lose it I want to use PHP's preg_match_all() function to search HTML files for <img> and <embed> tages and extract all the src URLs from those tags on a given HTML document. I want to cover all the possibilities and forms that those tages may be formated in. Here's an example with all the matches highlighted: <html> <body> <h1>Multimedia Page</h1> < img src="http://ex.com/img.jpg"> this is just an <img style='margin-top: 10px' src='http://ex.com/img.jpg' >example this is a falsh object <embed type="application/x-shockwave-flash" src=" width="425" height="350"></embed> this is another flash object <embed (there is a newline, a tab and a space characters seperating the rest of this tag from its opening <embed) type="application/x-shockwave-flash" src=" width="425" height="350"></embed> Here is another image tag <IMG (newline) (new line and tab) (new line) SRC="http://ex.com/img.jpg" HEIGHT="10">... <body> </html> The regex in words: MATCH THE FOLLOWING: <img (or <IMG) followed by any character (including spaces, tabs newlines with any count) followed by src= (or SRC=) which may be followed by a single or double quotation mark followed by anything (this is the URL part which will be the first set of matches stored in the multi-dimentional array generated by preg_match_all()) followed by an optional single or double quotation mark followed by optional anything (including spaces, tabs and newlines with any count) until the first > (not greedy) OR (|) MATCH THE FOLLOWING: the same scenario but this time for the <embed> tag and the URL (anything in regex) after src= as the second set of matches. I know that the regex would be only one line long or so, but writing all the above is much simpler, at least to me!
  6. OK, in a way or another my problem is now solved! Thanks all for your replies!
  7. If $i =0 then ${string2.$i} would be $string20, and ${string2.$i}[0] would be $string20[0]. What's the syntax error in the explode function. I want to split $string1 into strings bounded by double quote marks. the backslash is an escape char.
  8. Hello, What did I do wrong: for($i=1; $i<=5; $i++) { ${string2.$i} = explode("\"", $string1); } for($i=1; $i<=5; $i++) { echo ${relLink.$i}[0]; }
  9. Hello, I want to use a custom PHP script in my WordPress blog which uses the theme "mistylook-101". I want all the functions and variables set by WP to be defined in my custom script so that I can use functions like: get_header()... to apply the current theme to the custom script. What is the easiest way to do this? I tried placing the script file in: /wp-content/themes/mistylook-101 and then tried to use the function get_header() and others but of course non would work because non are defined for this "stranger" script! I also tried including some of the function files from wp-/includes/ but I got into a loop of "unable to open required file"... PS. I don't want to use plugins because my script has many PHP files that interact with its index file, I want to place my script's index file in the current theme directory so that it can use the current template (this is the problem as non of the WP functions/vars are defined to this file) and at the same time it interacts with the rest of the script files that are placed in another directory. Any help please?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.