Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find Character, Select Currency Code

    Alright So I cam trying to create a currency detection script and I got it all ironed out except for one part.

    Basically how it is going works is, it grabs the page content of http://www.xe.com/symbols.php and searches for the currency symbol in the example of this post the symbol ( ¥ ).

    Now I think I can find that symbol by doing a preg_match of that content which in the variable $data, but im not sure how to get it to grab the currency code from that same row in the table. I was thinking I might have to grab the whole <tr> and then search that, but Im not sure how i would do that either.

    Here is a 3 row example of the structure of that page

    Code:
    <tr class="row2">
         <td>Chile Peso</td>
         <td>CLP</td><td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">$</td>
         <td class="cSmbl_Fnt_AU">$</td>
         <td width="90px">36</td>
         <td>24</td>
         <td>	<a href="javascript:void(0);" class="curInfo">info</a></td>
    </tr>
    <tr class="row1">
         <td>China Yuan Renminbi</td>
         <td>CNY</td>
         <td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol165.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">¥</td>
         <td class="cSmbl_Fnt_AU">¥</td>
         <td width="90px">165</td>
         <td>a5</td>
         <td>	<a href="javascript:void(0);" class="curInfo">info</a></td>
    </tr>
    <tr class="row2">
         <td>Colombia Peso</td>
         <td>COP</td>
         <td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">$</td>
         <td class="cSmbl_Fnt_AU">$</td>
         <td width="90px">36</td>
         <td>24</td>
         <td>&nbsp;</td>
    </tr>
    So lets say $data is equal to that code above, How Would get the currency code when search for ( ¥ ) or how could I isolate that entire <tr> from the code.(I Could get the rest of it from there)

    Here is my code

    PHP Code:
    <?php

    if (!function_exists('bb_file_contents')) {
        function 
    bb_file_contents($url) {
            if(
    function_exists('curl_init')) {
                
    $ch curl_init();
                
    $timeout 0// set to zero for no timeout
                
                
    curl_setopt ($chCURLOPT_URL$url);
                
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                
    curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout);
                
    curl_setopt ($chCURLOPT_FOLLOWLOCATIONTRUE);
        
                
    $file_contents curl_exec($ch);
        
                if (!
    $file_contents) {
                    
    print_r(curl_getinfo($ch));
                    die;
                }
        
                
    curl_close($ch);
            }
            
            else {
                
    $file_contents file_get_contents($url);
            }
            
            return 
    $file_contents;
        }
    }

    $price '¥6.09';
    $convertURL 'http://www.xe.com/currencyconverter/convert/?Amount=6.09&From=CNY&To=USD';
    $currencyURL 'http://www.xe.com/symbols.php';

    echo 
    substr($price21);

    $data bb_file_contents($currencyURL);

    //Find Currency Code


    //Convert to other Currency

    ?>

  • #2
    New to the CF scene
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *bump*

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    738
    Thanks
    20
    Thanked 85 Times in 85 Posts
    something like this?

    PHP Code:

    $data 
    '<tr class="row2">
         <td>Chile Peso</td>
         <td>CLP</td><td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">$</td>
         <td class="cSmbl_Fnt_AU">$</td>
         <td width="90px">36</td>
         <td>24</td>
         <td>    <a href="javascript:void(0);" class="curInfo">info</a></td>
    </tr>
    <tr class="row1">
         <td>China Yuan Renminbi</td>
         <td>CNY</td>
         <td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol165.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">¥</td>
         <td class="cSmbl_Fnt_AU">¥</td>
         <td width="90px">165</td>
         <td>a5</td>
         <td>    <a href="javascript:void(0);" class="curInfo">info</a></td>
    </tr>
    <tr class="row2">
         <td>Colombia Peso</td>
         <td>COP</td>
         <td class="cSmbl_imgCol">
              <img src="http://s.xe.com/20100208/themes/xe/images/pages/curSymbols/curSymbol36.gif">
         </td>
         <td class="cSmbl_Fnt_C2000">$</td>
         <td class="cSmbl_Fnt_AU">$</td>
         <td width="90px">36</td>
         <td>24</td>
         <td>&nbsp;</td>
    </tr>'
    ;
    $findme1 '¥';
    $start1 stripos($data$findme1);
    $data1 substr($data$start1);

    $findme2 'width="90px">';
    $start2 stripos($data1$findme2);
    $data2 substr($data1$start2);

    $findme3 '<';
    $start3 stripos($data2$findme3);
    $data3 substr($data213,($start3-1));
    echo 
    $data3
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •