Jump to content

[SOLVED] fread problem or something


adv

Recommended Posts

hello

i have "file.txt"

 

in  the file.txt i have

user:password:question

user1:password1:question1

user2:password2:question2

$hand=fopen("file.txt","r")

and with curl i want to try multiple users at a time

$url='http://domain.com/file.php?go=&usr='.$usr.'&pass='.$pass.'question'.$question;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$res=curl_exec($ch);
curl_close($ch);

 

i`m stuck at fopen :|

 

Link to comment
Share on other sites

pff kinda hard

and i get the url with file_get_contents()

but how do i read through it and to try line by line... and extract each line in a variable or something .. and divide them to user pass and question...

or if there is a better way just tell me :D any help apreciated.

 

and a question that keeps bothering me

in php functions lets say strpos

you have strpos($str,"value");

does it counts the double quotes   is the same as strpos($str,'value');  ?

and not only in this function all php functions that uses string directly ...

Link to comment
Share on other sites

good good

but now how do i separate the line

 

user:password:question

 

$var1='user';  $var2='password'; $var3='question';  something like this

 

2)

and a question that keeps bothering me

in php functions lets say strpos

you have strpos($str,"value");

does it counts the double quotes  is the same as strpos($str,'value');  ?

and not only in this function all php functions that uses string directly ...

 

3)

and another one

why does some people use $var = "helllo {$name}";

when they still use double quotes

 

Link to comment
Share on other sites

Here is your first question, although I put it in arrays instead.

 

//Get the string you want to manipulate...
$string = "user:password:question";

//Create a new variable called array and make an array out of it
//but splitting the above string at all of the colon's.
$array = explode(":", $string);

/*
The $array variable will now look something like this:

Array (
	[0] => user,
	[1] => password,
	[2] => question
)

What this means is that we can access each of those elements by doing something like this:
echo $array[0];

That would give me 'user'.
*/

echo $array[0];

 

2) It does not count the quotes. The quotes simply mean you are passing a string. If you didn't have the quotes PHP would think you are trying to use a constant, but if no constant was found it will pass it as a string still. Even so, it's better to wrap it in the quotes.

 

3) The curly brackets inside a string are there so you can wrap variables in them. It's main use is for arrays. Consider the following example:

 

//We make an associative array, with the key being 'name' and the value being 'Jason'
$array = array("name" => "Jason");

/*
Now we can echo out the value of the array.
This methods requires you to 'break out' of the string to place in the array.
Oh and notice the single quotes around the key of the array.
Remember to always have them, otherwise PHP will again think you are talking about a constant.
*/
echo "Name: ".$array['name'];

/*
Another way to do it is using the { } that you mentioned above.
This way there is no need to break out of the string.
*/
echo "Name: {$array['name']}";

//Both of the above are valid, however. If you tried the following, it would result in an error.
echo "Name: $array['name']";

 

So as you can see the main purpose of the { and } are to allow you to put arrays in strings. You can also make variable variables out of them, but don't worry about that. :)

 

Hope I answered all your questions. Good luck!

Link to comment
Share on other sites

pff :( another problem

 

$ff=file_get_contents('file.txt');
$ss=explode("\n",$ff);
//print_r($ss);
$x=count($ss);
for($y=0;$y<$x;$y++){
$rss=$ss[$y];
$rss1=explode(":",$rss);
        //echo $rss1[0];
}
echo $rss1[0];

 

it echoes $rss1[0] inside for() but outside it doesnt echo nothing ... why`s that? :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.