/    Sign up×
Community /Pin to ProfileBookmark

Can’t get two stings to be equal…..

I’m at a loss. This is what I’ve done:

if ($_SESSION[‘log’] == ‘yes’) {
$to = file (‘messages_to.php’);
$from = file (‘messages_from.php’);
$message = file (‘messages_content.php’);
print ‘<div id=”content”>’;

if ($to[1] == $_SESSION[‘username’]) {
print ‘

<div id=”contitle”>From:’ . $from[1] . ‘</div>
<div id=”context”>’ . $message[1] . ‘</div>
‘;}

The username is the exact same string as the one on $to[1], but it’s not finding the two as equals and won’t print the rest of the stuff. Any explination as to why $to[1] and $_SESSION[‘username’] aren’t matching?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 07.2005 — A couple things to consider:

file() includes the newline character at the end of each line. So you probably need to rtrim($to[1]) either before or during the comparison.

Also, $to[1] will be the second line of the file. Is that what you intended, or do you really want the first line: $to[0] ?
Copy linkTweet thisAlerts:
@solidaritiDec 07.2005 — Have you tried putting ' ' around the [1]?
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 07.2005 — 

maybe you should trim the value from the file
--


edit: oops (see nogdog's post)
Copy linkTweet thisAlerts:
@NogDogDec 07.2005 — Have you tried putting ' ' around the [1]?[/QUOTE]
Shouldn't be necessary: file() returns integer array indices (starting with 0 for the first line).
Copy linkTweet thisAlerts:
@urquanmasterauthorDec 07.2005 — thank you so much. I didn't realize the lines have an invisable "n" on it.
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYDec 07.2005 — it's said in the manual: http://www.php.net/file
Note: Each line in the resulting array will include the line ending, so you still need to use rtrim() if you do not want the line ending present.[/QUOTE]
×

Success!

Help @urquanmaster 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,
)...