kenrbnsn
Staff Alumni-
Posts
8,234 -
Joined
-
Last visited
Everything posted by kenrbnsn
-
I looked at your code and the following might be a better way of doing what I think you're trying to do... <?php $file = file("input.txt"); $friends = array(); foreach ($file as $line) { $friend = trim($line); $friendInfo = explode(" ", $friend); $friends[$friendInfo[0]] = array('lat'=>$friendInfo[1],'long'=> $friendInfo[2]); } print_r($friends); ?> Ken
-
What does the input file look like? Ken
-
Popping and Integer as a time then looping until you reach the end...
kenrbnsn replied to HarryMW's topic in PHP Coding Help
Take a look at the function in this post. It's called time_duration. When used in a script, you pass it the duration in seconds and it returns a nicely formatted string: <?php echo time_duration('3645') . "<br>\n"; // prints 1 hour, 45 seconds echo time_duration('39547') . "<br>\n"; // prints 10 hours, 59 minutes, 7 seconds ?> See if you can use it in your script. Ken -
Can you post your code? Ken
-
Are you testing this using MSIE? MSIE only returns the x & y position of where you clicked in the image as $_POST['sucksbtn_x'] and $_POST['sucksbtn_y'] Ken
-
That "while" statement will never return an empty row. Ken
-
Popping and Integer as a time then looping until you reach the end...
kenrbnsn replied to HarryMW's topic in PHP Coding Help
Yes. I showed you a way to get the duration and echo Hour or Hours. That's what you asked. You didn't say what you wanted to do with it. Ken -
For that you probably have to use preg_replace(). Since I rarely use it, I can't give you any help. Ken
-
Popping and Integer as a time then looping until you reach the end...
kenrbnsn replied to HarryMW's topic in PHP Coding Help
Try <?php $duration = $end - $start; echo ($duration > 3600)?'Hours':'Hour'; ?> Ken -
Send the email before you use the mysql_real_escape_function on the variables. That function puts the "\" characters into the values. Ken
-
You shouldn't be using the mysql_real_escape_string() function if you're not going to be using the variables in a mysql query. Ken
-
Do only want to replace the '@' at the beginning of the words? So This is @test@ would become This is #test@ or do you want to replace all the '@' symbols in a string, so the test string becomes This is #test# If it's the first variant, you can do something like: <?php function at_to_hash($str) { return (ltrim(str_replace(' @',' #',' ' . $str))); } // //tests // echo at_to_hash('this is @test') . "<br>\n"; // result: this is #test echo at_to_hash('@this@') . "<br>\n"; // result: #this@ echo at_to_hash('@this is @a test') . "<br>\n"; // result: #this is #a test ?> Ken
-
You're explanation doesn't make a whole lot of sense. Please show examples (both before & after). Ken
-
Then you have to post the code for delete.php Ken
-
get_file_contents does not work with existing local files
kenrbnsn replied to techdude's topic in PHP Coding Help
In the second example, you're looking for a file contained in the variable $email_file which you haven't assigned a value to, so you get an error. Ken -
problem with array() while using the mail() function
kenrbnsn replied to firestarter30's topic in PHP Coding Help
I usually let PHP to the work for me: <?php $tmp = array(); $missing = array(); foreach ($_POST as $k=>$v) { switch($k) { case 'name': case 'email': case 'url': case 'title': case 'anchortext': case 'description': case 'dropdown': if (strlen(trim(stripslashes(strip_tags($v)))) > 0) { $tmp[] = ucwords($k) . ': ' . trim(stripslashes(strip_tags($v))); } else { $missing[] = $k; } break; } } $receiver = "example@gmail.com" ; if (empty($missing)) { $body = implode("\n",$tmp); $send = mail($receiver, 'Link Exchange Request', $body, "From: $email"); exit (json_encode(array('ret'=>'true'))); } else { exit (json_encode(array('ret'=>'false',implode(',',$missing)))); } ?> I'm assuming that you're getting a JSON error because this code is being called via AJAX. The "echo 'true'" is not a proper JSON string. The exit statements in my code above are proper JSON strings. Ken -
Popping and Integer as a time then looping until you reach the end...
kenrbnsn replied to HarryMW's topic in PHP Coding Help
You have to use time addition, not regular addition. Something like this: <?php $start = strtotime('3:00 PM'); $end = strtotime('10:00 PM'); $half_hour = 1800; // 1800 seconds in a 1/2 hour $tmp = array(); for($i = $start; $i <= $end; $i+=1800) { $tmp[] = date('g:i a',$i); } echo implode("<br>\n",$tmp); ?> Ken -
In this chunk of code <?php // get value of id that sent from address bar $id=$_GET['user_id']; ?> // Retrieve data from database <?php $sql="SELECT * FROM $tbl_name WHERE id=$user_id"; $result=mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_query()); ?> You assign a value to $id, but in the query you use $user_id. What I'm saying is that you probably want to use $id in your query: <?php // get value of id that sent from address bar $id=$_GET['user_id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id=$id"; $result=mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_query()); ?> Ken
-
You better modify your last post to remove the host, username, and password or change them on your site. You never assign a value to $user_id, maybe you want to use $id. Ken
-
If you had used my code, the query would have been printed out just before the error message. Please replace your code with my code and post the results. Ken
-
You never assign a value to $sp_users. I think you want to use $tbl_name. Replace <?php $sql="SELECT * FROM $sp_users WHERE id=$user_id"; $result=mysql_query($sql); $result=mysql_query("select * from $sp_users WHERE id=$user_id") or die(mysql_error()); ?> with <?php $sql="SELECT * FROM $tbl_name WHERE id=$user_id"; $result=mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_query()); ?> Ken
-
You don't want to use the "echo" in an assignment statement. Use <?php $delete = "<a href='delete.php?id=$id1'>Delete</a>"; ?> Ken
-
If you're duplicating all the code in similarly named files, you're doing something wrong. You should be able to make one php script to handle the work. Why do you think you have to make many scripts? Also, you shouldn't be using the session_register() function. Ken
-
If the code was working and now it's not, something changed. Did you change any code? Ken