Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

PHP variable help

Status
Not open for further replies.
Joined
Sep 28, 2006
Posts
402
Reaction score
6
I posted here because this isnt strictly a web design problem but hoping you can help (or point me in the right direction).

Im writting a PHP script to display data on a userbar which works

PHP:
$userbar_text = "Checked : 1 $xa of $x work";
imagestring($im, $font, 125,	3, $userbar_text, $colour);

The problem is that im wanting to move $userbar_text into a config file but cant get embedded $xa of $x to parse correctly.

So the above in short has become:-
config.inc.php
PHP:
$rsdata = array(
//		id		img		cl1	cl2	cl3	fnt	x		y	"text"
array(	"001",	"001",	0,	0,	0,	3,	125,	3,	"Checked : 1 \$xa of \$x work"),
array(	"002",	"002",	0,	0,	0,	3,	125,	3,	"Checked : 2 \$xa of \$x work"),
array(	"003",	"003",	0,	0,	0,	3,	125,	3,	"Checked : 3 \$xa of \$x work"),
);

script.php
PHP:
require_once('includes/config.inc.php');
...
...
foreach ($rsdata as $i => $tempvalue) {
	if ($imgnum == $rsdata[$i][0]) {
	$userbar_text = $tempvalue[8];
	$colour = imagecolorallocate($im, $tempvalue[2], $tempvalue[3], $tempvalue[4]);
	ImageFill($im, 0, 0, $grey);
	imagestring($im, $tempvalue[5], $tempvalue[6], $tempvalue[7], $userbar_text, $colour);
	}
}


but whatever I try, userbar displays either the text "Checked : 3 $xa of $x work" without changing $xa or $x or "Checked : 3 of work" with the variables being blank.
 
I'm not a php programmer, but I can't see where you are declaring what vars $x and $xa?

I'm guessing that $xa should be your $rsdata array length?
And $x is your current position in the array?
 
I get the impression this isn't the whole script.

As above $xa $ x aren't set, and when you split the array arrays into key value pairs where is imgnum set for the comparision with 001, 002 etc?

S
 
Yea thats far from the whole script as its a project in the making, but this might make it easier.

PHP:
require_once('includes/config.inc.php');
$xa = "apple";
$x = "plum";
echo $tempvalue[3][8];

Im wanting the script to output "Checked : 3 apple of plum work"
ive highlighted the vars taken from config.inc.php with $x $xa being substituted.


In the example posted $tempvalue[3][8] is the same but obviously this changes place and wording allowing the user to config the output.
 
After posting I reading some of your comments I googled for "replace" and came up with a answer to my problem.

preg_replace
^ ive not see this before but does the job :)

config now looks like this
PHP:
$rsdata = array(
//		id		img		cl1	cl2	cl3	fnt	x		y	"text"
array(	"001",	"001",	0,	0,	0,	3,	125,	3,	"Checked : 1 #xa# of #x# work"),
array(	"002",	"002",	0,	0,	0,	3,	125,	3,	"Checked : 2 #xa# of #x# work"),
array(	"003",	"003",	0,	0,	0,	3,	125,	3,	"Checked : 3 #xa# of #x# work"),
);

and the script using preg_replace
PHP:
foreach ($rsdata as $i => $tempvalue) {
	if ($check_user == $rsdata[$i][0]) {
	$imgnum = $tempvalue[1];
	}
	if ($imgnum == $rsdata[$i][0]) {
	$userbar_text = preg_replace("/#xa#/", $xa, $tempvalue[8]);
	$userbar_text = preg_replace("/#x#/", $x, $userbar_text);
	$colour = imagecolorallocate($im, $tempvalue[2], $tempvalue[3], $tempvalue[4]);
	ImageFill($im, 0, 0, $grey);
	imagestring($im, $tempvalue[5], $tempvalue[6], $tempvalue[7], $userbar_text, $colour);
	}
}


Thanks for your comments, from this I was able to find an answer via google.
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom