Jump to content

adrianTNT

Members
  • Posts

    146
  • Joined

  • Last visited

Posts posted by adrianTNT

  1. You might consider setting $comments as a constant instead. That automatically makes it global.

    define('COMMENTS_PER_PAGE', 10);

    then in the function use it

    print COMMENTS_PER_PAGE;

    If you want to be able to change it that won't work, but as you said it's a setting I figure a constant will work better.

    Yes, it is a setting and making it constant as you said could work, but I have more variables to use in same script and I was trying to figure out the way I have to use the other ones too.

     

    Inside the function you need to use global $comments_per_page; before using it. That way you use the global instead of the local.

    Outside of the function I believe you can just use $comments_per_page.

    However, if you wish to be exactly sure about it, you can use $GLOBALS['comments_per_page'].

    so if inside a function I add

    global $comments_per_page and after that I change it's value inside the same function does this mean the variable value is also changed globally? Or only temporary to be used inside that function?

     

  2. Hello.

     

    I have a variable called $comments_per_page that is inside settings.php, ($comments_per_page = 10);

    Then a main file comments.php that contains:

    <?php
    // include settings.php that contains the value of $comments_per_page
    require settings.php;
    
    function some_function(){
    // I need to use $comments_per_page here (inside a function)
    }
    // I also need to use $comments_per_page here (outside of the function)
    ?>

     

    I dont know how to access and use the variable $comments_per_page when inside or outside of a function, I know about 2 things but I am not sure how to use them:

    $GLOBALS['comments_per_page'];

    global $comments_per_page;

     

    - Which one of these 2 ^ I need to use inside and outside of a function when accessing and modifying $comments_per_page variable?

    - When I just have "$comments_per_page = 10" inside settings.php does that mean it was created as a global variable?

     

    Thank you.

    - Adrian.

  3. just a simple typo, send godaddy an email about it.

    I don't know if they deserve it, when I have a problem and I ask them they are like:

    "- Not our problem, you should have paid for assistance service" (assistance is something over $100, few months minimum).

    But I will send them an email about the typo in their help files.

     

    Anyway ... their support is as bad as people said it is, I had more problems with their support staff for different services of theirs. I think they got so big that they ran out of good techies.

  4. Thanks WildTeen88, but the problem was something else, I managed to fix it by changing some system files on the server.

    From what I understood it didnt allowed me to run scripts in that directory inside the site, it somehow had a predefined directory inside the site where I could run scripts, I edited system files and set that directory to site root then it worked.

     

    The host has the solution here:

    http://help.godaddy.com/article.php?article_id=1619&topic_id=&prog_id=GoDaddy&

    create a vhost.conf file in your /var/www/vhosts/domain.com/conf/ directory, and enter the following lines:

     

    <Directory /var/www/vhosts/domain.com/httpdocs>

    php_admin_value open_basedir /path/you/require:/another/path/you/require

    <Directory>

     

    But I was surprised to see that the instructions ware incorrect, for example that XML syntax ^ doesn't close the XML tags properly in their example so if you try exact same thing will not work.

     

    This one worked:

    <Directory /var/www/vhosts/domain.com/httpdocs/>

    php_admin_value open_basedir /path/you/require:/another/path/you/require

    </Directory>

  5. Corbin, the plain file is stored as _id_of_item_to_be_rated.dat and there is a .dat file for each item id to be rated.
    An example of database file woudl be: video1.dat and its contents is like this:

    3|68.117.115.182
    5|34.117.115.122

    that is user's vote (1..5) | user's ip.

    now maybe the script can do this....
    get an array of IDs from the user (items to be rated, e.g video1,video2,video3) and from same directory as the php file read the dat file for each one of them, calculate the average (1 to 5) then print them in the right order, this print will later be the display of the swf file.

    video1 score 5
    video2 score 3
    video3 score 1

    Do I make sense ?
  6. Hello.
    I am not very familiar with mod rewrite. It looks like it can have many options and code inside can get very complex.
    What I need is only this:

    display the contents of:
    site.com[b]/read.php?cat=tutorials[/b]
    by accessing:
    site.com[b]/tutorials/[/b]

    How should the .htaccess look like?
    Thank you.
  7. The system doesn't use a database. It saves to plain file.
    Maybe is not such a good idea to use my rating system in this case.

    Or if you want to use it then easiest way would be to talk to a php developer after you have the rating system so that person can see the code and chose best solution.
    When a php developer sees the system it should be easy for him to do the additional code that sorts the swf files inside html code.
    What I had in mind is a php script that orders the html code for displaying each swf file in correct order.
  8. Hello.

    // I am the one that sells the product.

    Since I am a flash developer myself (not php developer), the php part of this product was made by someone else so I cannot make such updates that require additional php coding, this is why I suggested to the user that he should ask here about such php modifications.

    Here are some details about how it words, maybe someone knows how it should be done.
    The rating system is a swf file that sends and loads data by a php file in background, the flash file sends an id (photo1, photo2) ot the php file and the php file returns the rating score (1..5) and flash file shows the stars (1..5).

    I think this could be done by adding php script inside the html code of same page, send the id of all items to be rated to the php file and record the answers then display the swf files in the right order according to the answers received.

    [code]<?php

    $my_ids = array ('photo1','photo2','photo3');
    $my_scores = array ();

    send the id 'photo1' to the php (by GET I think) and record the answer (score 1..5);
    send the id 'photo2' to the php (by GET I think) and record the answer (score 1..5);
    send the id 'photo3' to the php (by GET I think) and record the answer (score 1..5);

    Display the html code to show all swf files in the order according to the scores received above.

    ?>[/code]

    That should be a way to do it but I don't know if is possible without the product code and since is commercial product I cannot post he files for download.
  9. [quote author=effigy link=topic=121560.msg500100#msg500100 date=1168296369]
    Good programming is not only about "working," but also about using the right tools; optimization. Are you going to rent a moving van to haul a box of books when you have a Pinto sitting in the drive way? They both work (Pinto jokes aside)....

    I thought php.net used to have a blurb in the preg_replace docs about using str_replace for fixed replaces, but I could be wrong. They do have one about using strpos or strstr instead of preg_match, because it's faster. Perhaps it doesn't matter between preg_replace and str_replace, and in our days of fast machines it may not even be a big deal (depending on the usage), but, hopefully you get my point :)
    [tt]</ramble>[/tt]
    [/quote]
    yes, I think I get your point but I am a PHP biginner and I am not very familiar with most of the functions.
  10. [quote author=effigy link=topic=121560.msg500076#msg500076 date=1168294569]
    See [url=http://www.phpfreaks.com/forums/index.php/topic,120594.msg496080.html#msg496080]this[/url] post.
    If you're not using patterns, don't use preg.
    [/quote]
    Effigy , why not ? It seems to work.

    I got rigd of that warning above, I think I had some slashes entered in bad locations.

    Thank you all for your help. I like this forum :)
  11. ok, I used preg_replace and seems to do what I need but I get an error and I dont understand it:

    [code]<?php
    $string = 'visit my site http://www.google.com or www.msn.com or at least yahoo.com';
    //
    $patterns = array('/http://www./','/https://www./','/http/','/www./','/.com/','/.net/','/.org/','/.biz/','/.info/','/:\/\//');
    //
    echo preg_replace($patterns, ' ... ', $string);
    //
    ?>[/code]

    It says:

    [quote][b]Warning: Unknown modifier '/' in /var/www/vhosts/adriantnt.com/httpdocs/temp.php on line 6

    Warning: Unknown modifier '/' in /var/www/vhosts/adriantnt.com/httpdocs/temp.php on line 6[/b]
    visit my site ... ... ... google ... or ... msn ... or at least yahoo ... [/quote]
  12. Hello.

    I have this php script that displays the contents of an xml file like this:

    [code]
    <?xml version="1.0" encoding="iso-8859-1"?>
    <icons>
    <ico title="Lino Adium Dock" img="enhancedlabs/lino_adium_dock.png" url="http://www.enhancedlabs.com"/>
    <ico title="The real Christmas" img="enhancedlabs/2005.png" pc="enhancedlabs/the_ico.zip" url="http://www.enhancedlabs.com"/>
    <ico title="Mac Mini" img="enhancedlabs/mac_mini.gif" pc="enhancedlabs/mac_mini_icons.zip" url="http://www.enhancedlabs.com"/>
    </icons>
    [/code]

    The script to print the above xml file is like this:

    [code]
    <?php

    class XMLparser{
    var $main = array();
    var $currentparent = "default";
    function XMLparser($inputxmlstring){
    $lines = explode("\n",$inputxmlstring);
    $n = 0;
    foreach ($lines as $line){
    if (trim($line) == "") continue;
    $line = trim($line);
    $s_regex = "/<([a-z]+)>/i";
    $e_regex = "/<\/([a-z]+)>/i";
    $s_matches = null; $e_matches = null;
    $start = preg_match($s_regex, $line, $s_matches);
    $end = preg_match($e_regex, $line, $e_matches);

    if ($s_matches == null && $e_matches == null){
    //this is a node
    $attributes = array();
    preg_match_all("/([a-z]+)=\"([^\"]*)\"/i", $line, $attributes);
    $names = $attributes[1];
    $values = $attributes[2];
    for ($i = 0; $i < count($names); $i++){
    $name = $names[$i];
    $value = $values[$i];
    $this->main[$this->currentparent][$n][$name] = $value;
    }
    $n++;
    }else if($e_matches == null){
    //this is a start
    $parentname = $s_matches[1];
    $this->currentparent = $parentname;
    $n = 0;
    }
    }
    }
    }

    $XML = file_get_contents("icons.xml");

    $instance = new XMLparser($XML);
    $parseddata = $instance->main;

    //get all the nodes under the "icons" parent
    /*
    foreach ($parseddata['icons'] as $node){
    echo "Title: " . $node['title'];
    echo " Source: " . $node['img'];
    echo " Credits: " . $node['url'] . "<br />";
    }
    */
    ?>
    [/code]

    [color=red][b]Question is: how should the parser look like in order to parse a new XML file formated like this:[/b][/color]

    [code]<?xml version="1.0" encoding="iso-8859-1"?>
    <links>
    <link>
    <title>Adrian TNT Flash Design</title>
    <url>http://www.adriantnt.com</url>
    <description>Flash menus, buttons and components by Adrian. C.</description>
    </link>
    <link>
    <title>FFILES</title>
    <url>http://www.ffiles.com</url>
    <description>Sharing resources and creations.</description>
    </link>
    </links>
    [/code]

    Thank you.
    - Adrian.
  13. Hello, I thought it should be something easy but I cannot find a simple sample code for this...
    I have more images that are saved as 250x250px on server and I need to display them on some page as lower size, e.g 125x125px.
    I do not need to physically store them at the new size.
    I thought it should be an easy way like:

    <img src=" <? GD_resize('my_image.jpg',125,125);?> " width="250" height="187">

    But I could not find a sample like this. Is there a way to resize an image like above?

    Thank you.
    - Adrian.
×
×
  • 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.