Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
convert var[#] to string
Old 07-21-2009, 09:13 PM convert var[#] to string
Experienced Talker

Posts: 41
Trades: 0
how do you convert a var[#] to a string, what im trying to do is load a image file with the string from the var[#] but the script reads the image as var[#].bmp instayed of the string that the var[#] represents
flatrat is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-21-2009, 10:29 PM Re: convert var[#] to string
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Is var[#] an array? Try print_r or var_dump.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-21-2009, 11:15 PM Re: convert var[#] to string
Experienced Talker

Posts: 41
Trades: 0
thanks for all the help nullpointer,
unfortunelty nither of thoes solutions worked, print_r comes back as 1 and var_dump comes back as null,

my main issue is with this
Code:
echo '<img src="($expo[1]).bmp" width="50" height="50">';
(its at the bottem im trying to test it before adding it to the loop)
im sure thats entirely wrong, i may of been closer with other wrong attempts but this is where my back button takes me , when the site loads, the image thats spose to load comes up as ($expo[1]).bmp instayed of its target,

this is the full page
Code:
<?php
$i = 0;
$linenum = $i ;
$path = "map2.txt"; 
$handle = fopen($path, "r"); 
$lines=file($path); 
$string[$i] = ($lines[$linenum]);  
$expo = (explode("|",($string[$i])));
$string2[$i] = str_word_count($string[$i]) ; //get Len //
 
$counter = 0;
while ( $counter <= 10 ) {
  $expo = (explode("|",($lines[$counter])));
  echo ($expo[1]);
  echo ($expo[2]);
  echo ($expo[3]);
  echo ($expo[4]);
  echo ($expo[5]);
  echo ($expo[6]);
  echo ($expo[7]);
  echo ($expo[8]);
  echo ($expo[9]);
  echo ($expo[10]);
  echo "<BR />"; 
  echo str_word_count($lines[$counter]);
$expo = (explode("|",($lines[$counter])));
  echo "<BR />"; 
 $counter = $counter + 1;
 }

echo '<img src="($expo[1]).bmp" width="50" height="50">';
 
?>
this is map2.txt
Code:
a1|b1|c1|d1|e1
a2|b2|c2|d2|e2
a3|b3|c3|d3|e3
a4|b4|c4|d4|e4
a5|b5|c5|d5|e5
flatrat is offline
Reply With Quote
View Public Profile
 
Old 07-22-2009, 12:14 AM Re: convert var[#] to string
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Strings surrounded with single quotes ( ' ) are not parsed so
PHP Code:
echo '<img src="($expo[1]).bmp" width="50" height="50">'
will literally output the string <img src="($expo[1]).bmp" width="50" height="50">

Variables are parsed in double quotes, however. In some cases you need to surround your variables with braces {}, not parens () to indicate that the variables needs to be parsed. Try:
PHP Code:
echo "<img src=\"{$expo[1]}.bmp\" width=\"50\" height=\"50\">"
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-22-2009, 12:43 AM Re: convert var[#] to string
Experienced Talker

Posts: 41
Trades: 0
yea that works, took some fiddleing around with tho, after the loop it seems to of forgot what expo[0] is, is there a way to read a exploded array, with two integers, like expo[0][0] or is the best way to store them in other arrays as i make them

thanks you again,

Last edited by flatrat; 07-22-2009 at 12:53 AM..
flatrat is offline
Reply With Quote
View Public Profile
 
Old 07-22-2009, 01:02 AM Re: convert var[#] to string
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
print_r($expo); 
That should display all of the values in the array. The output is plain text, not html so it is easier to read if you view the source rather than just the browser output.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 07-22-2009, 01:20 AM Re: convert var[#] to string
Experienced Talker

Posts: 41
Trades: 0
is it possible to place a image ontop of another image

Last edited by flatrat; 07-22-2009 at 03:31 PM..
flatrat is offline
Reply With Quote
View Public Profile
 
Old 07-23-2009, 03:28 AM Re: convert var[#] to string
moatist's Avatar
Skilled Talker

Posts: 64
Trades: 0
It is possible to parse strings within single quotes:

PHP Code:
echo '<img src="'.($expo[1]).'.bmp" width="50" height="50">'
__________________
Think in code; Dream in digital.

<?php if($helpfull == true){ $talkupation++; } ?>
moatist is offline
Reply With Quote
View Public Profile
 
Old 07-23-2009, 04:01 AM Re: convert var[#] to string
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by moatist View Post
It is possible to parse strings within single quotes:

PHP Code:
echo '<img src="'.($expo[1]).'.bmp" width="50" height="50">'
The string isn't parsed, it is three seperate strings appended together. In double quotes the string itself is parsed.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to convert var[#] to string
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.68085 seconds with 12 queries