/    Sign up×
Community /Pin to ProfileBookmark

extract first two letters

Now I’m just trying to take the first two letters from an array and print them. The string that the characters are coming from is coming from the $_POST array and is the 0 element. This is what I have:

[code=php]
$langFromArray[] = “”;
for($i = 0; $i <2; $i++) {
$langFromArray[$i] = $myVars[0][$i];
}
$langFrom = $langFromArray[0] . langFromArray[1];
print(“This was translated from ” . $langFrom “.”);
PHP]

the error says, “unexpected ‘[‘ ” on the line that begins, “$langFrom = “. Does PHP not handle strings as arrays, b/c that’s all that I can figure…

I’m sure there’s another way to do this so if anyone knows it or sees what I’m doing wrong, I’d appreciate it very much.

thanks, holly

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@bmoremusauthorApr 13.2004 — I forgot to mention that $_POST has been assigned to $myVars.

h
Copy linkTweet thisAlerts:
@solavarApr 13.2004 — You've got a typing error here:

<i>
</i>$langFrom = $langFromArray[0] . [COLOR=crimson]langFromArray[/COLOR][1];


You've left out the [B]$[/B]
Copy linkTweet thisAlerts:
@bmoremusauthorApr 17.2004 — Sorry it's taken me so long to get back to this...

I must have mis-copied my code because I did have a $. Thanks, though.

Here is the code chunk:

[code=php]<?php
$langFromArray[] = "";
for($i = 0; $i <2; $i++) {
$langFromArray[$i] = $myVars[$i];
}
[COLOR=crimson]$langFrom = $langFromArray[0] . langFromArray[1];[/COLOR] [COLOR=orangered]$langFrom = $langFromArray[0] . langFromArray[1];[/COLOR]
print("This was translated from " . $langFrom ".");
?>PHP]

and the eror is:


Parse error: parse error, unexpected '[' in f:student-iatdynamichspharhomeworktranslationservicehermesita-d3-go.php on line 180[/QUOTE]

181 is the line shownin red.
Any ideas?

holly
Copy linkTweet thisAlerts:
@bmoremusauthorApr 17.2004 — that duplicate line doesn't appear in my code; I was having I did''t notice that it was added twice when I colorized it.

holly
Copy linkTweet thisAlerts:
@bmoremusauthorApr 17.2004 — Okay, I'm sorry, I missed the problem. I could've sworn that the $ was there a couple seconds ago.

h
×

Success!

Help @bmoremus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...