Jump to content

etrader

Members
  • Posts

    315
  • Joined

  • Last visited

    Never

Posts posted by etrader

  1. I have searched a lot but no information about this aspect. I wonder how much heavy is the process of getting parts of a webpage by preg_match?

     

    But my question is that which of these options are in favor of lighter CPU process:

     

    1. getting each item between specified tags by a preg_match

    or

    2. First getting the content between <body>, then processing by php tools such as preg_match (again), explode, etc.

     

    Thanks for considering this unusual question  :D

  2. I have search page in the form of search.php?q=query, as the php script calls for other files and a long process. When visiting search.php directly, the value of q is indeed null, and it makes a long loop and use lots of cpu.

     

    How to kill the script or redirect to the main page when visiting search.php?

  3. There is a "PHP ajax cascading dropdown using MySql" at codestips.com/php-ajax-cascading-dropdown-using-mysql/

     

    I want to use this technique but with a XML or array file instead of mysql database, but my knowledge about mysql is very low. How I can modify this code to catch the categories and products from an array, instead of mysql database?

     $connect=mysql_connect($server, $db_user, $db_pass)
          or die ("Mysql connecting error"); 
    echo '<table align="center"><tr><td><center><form method="post" action="">Category:<select name="category" onChange="CategoryGrab('."'".'ajaxcalling.php?idCat='."'".'+this.value);">';
    $result = mysql_db_query($database, "SELECT * FROM Categories");
    $nr=0;
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    $nr++;
    echo "<option value=".'"'.$row['ID'].'" >'.$row['Name']."</option>";
    }
    echo '</select>'."\n";
    echo '<div id="details">Details:<select name="details" width="100" >';
    $result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=1");
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
     echo "<option value=".$row['ID'].">".$row['Name']."</option>";
    }
    echo '</select></div>';
    echo '</form></td></tr></table>';
    mysql_close($connect);

     

    ajaxcalling.php is

    include("config.php");
    $ID=$_REQUEST['idCat'];
    $connect=mysql_connect($server, $db_user, $db_pass);
    echo 'Details:<select name="details" width="100">';
    $result = mysql_db_query($database, "SELECT * FROM CategoriesDetails WHERE CategoryID=".$ID);
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
     echo "<option value=".$row['ID'].">".$row['Name']."</option>";
    }
    echo '</select>';
    mysql_close($connect);

     

  4. I want to have a multi level dropdown selection tool come out of an array (not database; almost all of available codes on the internet are based on mysql databse). I have an array as each element has this format: "Country | City | ID". Using explode, I want to make a dropdown to choose the country, then choosing the cities of the chosen country. Finally, in a simple search box make action="result.php" to lead to result.php?q=$id

     

    Thanks for your kind attention  :shy:

  5. I have lists of links in different pages. I want to add an option for the visitors to add favorite ones to a list (like add to cart in shopping sites), and finally see the links selected in a page. This is based on the visitor's browser cookies.

     

    What is the simple way to do this (without database). Actually I need a function to save the items in the browser cookies and then retrieve them.

  6. When I used Amazon API to capture a product details using the well known code (http://www.chipdir.nl/amazon/aws_signed_request.phps), It made this error, and consequently lots of CPU usage which made my server down.

    [14-Mar-2011 20:38:01] PHP Warning:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: uestProcessingTime>0.0009990000000000</RequestProcessingTime></OperationRequest> in /home/laptop/public_html/jewelryaccessories.us/amazon.php on line 52

     

    Line 51 - 60 of amazon.php is

            // parse XML
            $pxml = simplexml_load_string($response);
            if ($pxml === False)
            {
                return False; // no xml
            }
            else
            {
                return $pxml;
            }

     

     

  7. This solution is perfect, but is it possible to get the file extension from the downloaded file?

     

    Now we get the extension from the $test string, but if downloading from e.g. file sharing websites, the url may not include the file name. And additionally, if the rar or zip file contains part1 part2, it will be considered as a part of the file name. I think if first downloading the file on the server, we can get the file information, then renaming.

     

    I have explored some codes, but none of them are comparable with your elegantly short idea; this is the reason that I continue this thread.

     

    Thanks  ::)

  8. I have html files with this format

    .....
    <!--ImageSection--><div class="image"><!--ImageSection--><div align="top"><b>Image Link</b>
    <br />http://www.something.com
    <br />http://www.another_url
    <br /></div><!--ImageEnd--></div><!--ImageEnd--></div> 
    .....

     

    I tried to get the content of a <div> with this code:

    preg_match_all('/<div class=\"image\">\<!--ImageSection-->\<div align=\"top\">([^`]*?)<\/div>/', $html, $imglinks);
    foreach ($imglinks as $imglink){
    echo $imagelink;
    }

     

    but it returns empty, where did I wrong?  :-[

  9. I want to select some strings from an array (list of urls) with this code

    $pattern = "/books/";
    if(preg_match($pattern, $list)) {

     

    I have two questions:

     

    1. When I put "/5" as the pattern (I mean having a term in the url starting with 5), I get this error: Warning: preg_match() [function.preg-match]: No ending delimiter '/' found

     

    2. What if I want to add two if conditions? I mean if the string contains "/books/" and "/5" ?

     

    ;D

     

×
×
  • 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.