adv Posted September 21, 2008 Share Posted September 21, 2008 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 :| Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 22, 2008 Share Posted September 22, 2008 Use file_get_contents(). Quote Link to comment Share on other sites More sharing options...
adv Posted September 22, 2008 Author Share Posted September 22, 2008 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 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 ... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 22, 2008 Share Posted September 22, 2008 If you want the read the file line by line then you can do the following: $file = file("path/to/file.txt"); foreach($file as $line){ echo $line."<br />"; } That will loop through and echo out all the lines. Quote Link to comment Share on other sites More sharing options...
adv Posted September 22, 2008 Author Share Posted September 22, 2008 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 Quote Link to comment Share on other sites More sharing options...
adv Posted September 22, 2008 Author Share Posted September 22, 2008 plzz anybody Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 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! Quote Link to comment Share on other sites More sharing options...
adv Posted September 23, 2008 Author Share Posted September 23, 2008 thanks alot Fear i think i got it :* Quote Link to comment Share on other sites More sharing options...
adv Posted September 23, 2008 Author Share Posted September 23, 2008 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? Quote Link to comment Share on other sites More sharing options...
adv Posted September 24, 2008 Author Share Posted September 24, 2008 nevermind i got it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.