hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP some code help needed please
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP some code help needed please

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-24-2006, 06:14 PM
UH-Matt UH-Matt is offline
Corporate Member
 
Join Date: Aug 2002
Location: London, UK
Posts: 9,027

PHP some code help needed please


Im not very good with PHP but I want to try and do this.

Lets assume I have a url to a text file containing a number,

www.somedomain.com/somefile.txt

This file may contain a number 9234 or 10394 or anything else.

I want some php code that will read that text file number, and then create a graphic of that number using individual number files.

So I may have:

1.gif , 2.gif , 3.gif , 4.gif , 5.gif , 6.gif , 7.gif , 8.gif , 9.gif , 0.gif , comma.gif

--

So the code will read that text file and see the number is 10123 and it will build the following code:

<img src="images/1.gif"><img src="images/0.gif"><img src="images/comma.gif"><img src="images/1.gif"><img src="images/2.gif"><img src="images/3.gif">

This would in turn build an image of 10,123 out of the images i have created....

Im sure you understand what i need any code appreciated.

__________________
Matt Wallis
United Communications Limited
High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

Reply With Quote


Sponsored Links
  #2  
Old 01-24-2006, 06:25 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
PHP Code:
<?php
    $file 
file_get_contents('somefile.txt');
    
$file explode("\\",$file);
    foreach(
$file as $key => $value) {
        echo 
"<img src=\"$value.gif\" />";
    }
?>
There are better ways of doing what you described, but the above should work.

Reply With Quote
  #3  
Old 01-24-2006, 06:26 PM
UH-Matt UH-Matt is offline
Corporate Member
 
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
What about adding the comma in the right place to seperate thousands?

__________________
Matt Wallis
United Communications Limited
High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

Reply With Quote
Sponsored Links
  #4  
Old 01-24-2006, 06:29 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
PHP Code:
<?php
    $file 
file_get_contents('somefile.txt');
    
$file number_format($file);
    
$file explode("\\",$file);
    foreach(
$file as $key => $value) {
        if(
$value == ',') {
            
$value 'comma';
        } elseif(
$value == '.') {
            
$value 'dot';
        }
        echo 
"<img src=\"$value.gif\" />";
    }
?>


Last edited by Dan L; 01-24-2006 at 06:36 PM.
Reply With Quote
  #5  
Old 01-25-2006, 12:04 AM
UH-Matt UH-Matt is offline
Corporate Member
 
Join Date: Aug 2002
Location: London, UK
Posts: 9,027
Ok

The text file im reading doesnt have a comma, but I want the final image to display the comma in the right place.

So now the code needs to take the number and work out how many digits are in it, and work out if/where a comma image should be displayed...


__________________
Matt Wallis
United Communications Limited
High Performance Shared & Reseller | Managed VPS Cloud | Managed Dedicated
UK www.unitedhosting.co.uk | US www.unitedhosting.com | Since 1998.

Reply With Quote
  #6  
Old 01-25-2006, 02:35 AM
Burhan Burhan is offline
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,100
PHP Code:
$number number_format(trim(file_get_contents("number.txt")));
$size strlen($number);
for(
$x 0$x $size$x++)
{
   if (
$number{$x} === ',')
   {
       echo 
'<img src="comma.gif">';
   } else {
       echo 
'<img src="'.$number{$x}.'.gif">';
   }


__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

Reply With Quote
  #7  
Old 01-25-2006, 03:28 PM
Dan L Dan L is offline
Web Developer
 
Join Date: Feb 2003
Location: Connecticut
Posts: 5,441
fyrestrtr's way is better, the trim() is important.

FYI, number_format automatically adds the commas into the number.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Cloud Industry Forum Establishes Cloud Service Provider Code of Practice Web Hosting News 2012-09-21 12:38:23
DigiCert Launches Extended Validation Code Signing Certificates Web Hosting News 2012-08-15 15:30:28
Non-Profit New Zealand Computer Society to Develop Cloud Code of Practice Web Hosting News 2011-09-02 17:22:36
SSL Certificate Authority Comodo Providing Intel Application Certification Web Hosting News 2011-08-12 15:51:28
Web Host DreamHost Contributing Code for Ceph File System to OpenStack Web Hosting News 2011-06-23 20:40:32


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?