- Strength to Increase Rep
- +8
- Strength to Decrease Rep
- -2
- Upvotes Received
- 29
- Posts with Upvotes
- 24
- Upvoting Members
- 21
- Downvotes Received
- 3
- Posts with Downvotes
- 3
- Downvoting Members
- 3
94 Posted Topics
Re: I think this would work reasonably fast: [CODE]<?php $filename = "/path/to/file.txt"; $handle = fopen($filename,"r"); if ($handle === false) { exit; } $word = ""; while (false !== ($letter = fgetc($handle))) { if ($letter == ' ') { $results[$word]++; $word = ""; } else { $word .= $letter; } } fclose($handle); … | |
Re: You want this: [CODE]<input type="image" src="blah.png">[/CODE] | |
![]() | Re: My approach would be to create not so much as a database but just a flat file, say tab delimited. You can read the entire thing into memory with PHP and manipulate the data as needed. You could either run a web server locally (Macs have this already built in) … ![]() |
Re: The dots get changed to underscores. So use this instead: $linex = $_GET['shapes_image_x']; $liney = $_GET['shapes_image_y']; | |
Re: The Content-Type header must be sent before the Content-Disposition header. | |
Re: Neither of these are the correct approach. strtotime turns the date into an integer. You then subtract one integer from the other which gives you a difference. You are then trying to turn that difference into a date (which will result in a date close to the epoch depending in … | |
Re: Of course. Usually it's in /usr/bin/php Use this syntax: [CODE]/usr/bin/php[I] filename.php[/I][/CODE] | |
Re: Use the $_SESSION array instead. So, for example: [CODE]$_SESSION["name"]="foobar";[/CODE] So now you should not use session_register(), session_unregister() or session_is_registered(). Can you can test using: [CODE]if (isset($_SESSION["name"])) { ... }[/CODE] | |
Re: PHPShadow: [URL="http://www.phpshadow.com"]http://www.phpshadow.com[/URL] This is probably the most cost effective solution because you only need to buy a licence (5 euro) when you encrypt your source code. Once encrypted, your source code will work forever and you don't have to pay them another penny. | |
![]() | Re: [CODE]<?php function find_value($input) { // $input is the word being supplied by the user $handle = @fopen("/users/edwin/list.txt", "r"); if ($handle) { while (!feof($handle)) { $entry_array = explode(":",fgets($handle)); if ($entry_array[0] == $input) { return $entry_array[1]; } } fclose($handle); } return NULL; } ?>[/CODE] |
Re: You're only opening the file. You're not outputting it. Try changing [CODE]$file=fopen("welcome.txt","r");[/CODE] to [CODE]readfile("welcome.txt");[/CODE] | |
Re: PHPshadow ([url]http://www.phpshadow.com[/url]) encrypts PHP code, and requires a license code (a file) to be copied onto the server before it will work. One option is a 50 Euro one-off payment per customer (it's locked to a specific domain name). The other option is an annual payment of 20 Euro. Because … | |
Re: I presume you're using PuTTY to initiate an SSH connection. If so, try the editors [B]nano[/B] or [B]pico[/B] e.g. nano index.php | |
Re: Are you sure you have the [URL="http://www.php.net/manual/en/book.sockets.php"]sockets module[/URL] installed in your PHP installation? Check by looking at the output of phpinfo() | |
Re: Just elaborating on twiss's post: [CODE=HTML]<script type="text/javascript"> function doSomething(elem) { alert ('The ID of the element which triggered this is: ' + elem.id; } </script> <div id="blah" onClick="doSomething(this)">Blah blah blah</div>[/CODE] | |
| |
Re: [QUOTE=tnjiric;1607096][CODE]echo substr($search,0,4); //this would print out "Hello"[/CODE][/QUOTE] Not quite. That would print out "Hell" (4 characters) | |
Re: I agree with evstevemd. [CODE]foreach ($array as $key => $value) { echo 'The key is '.$key.' and the value is '.$value; }[/CODE] $key and $value are created as part of the foreach statement. | |
Re: You can use cron to call a php page. IN your crontab file, the command part would be something like this: [CODE=shell]/usr/bin/php /users/me/www/myfile.php[/CODE] | |
Re: [QUOTE=Shantanu88d;1588131]ok but, in case when we have an entire text file containing thousands of words, what approach can we take ?[/QUOTE] See here: [url]http://www.daniweb.com/web-development/php/threads/369522[/url] | |
Re: [CODE]<?php $text = "one\ntwo\nthree\nfour"; echo preg_replace("/\\n/m"," \n",$text); ?> [/CODE] | |
Re: This page does the calculation. It uses DateInterval so requires PHP 5.3.0 or later. [CODE]<?php $age = $_GET["age"]; $year = $_GET["year"]; $month = $_GET["month"]; $day = $_GET["day"]; if (!$_GET["age"]) { } elseif (!checkdate($month,$day,$year)) { echo "Invalid Date"; } else { $one_year = new DateInterval("P1Y"); $one_day = new DateInterval("P1D"); $age_years = … ![]() | |
Re: Here I'm assuming you will be executing the code as the user logs in. So you can do this: [CODE]$random_hour = randbetween(0,23); $current_hour = date("G",time()); if ($current_hour == $random_hour) { // something great happens }[/CODE] If you're trying to implement it on a weekly cycle (i.e. choosing a random hour … | |
Re: It's easier to troubleshoot if you arrange your code neatly, like this:[CODE=php]<?php if (empty($mobile)) { echo '<script language="javascript">alert("Enter Phone Number")</script>;'; } elseif (!(empty($mobile))) { if ((is_numeric($mobile))) { if ((strlen($mobile)!=10)) echo '<script language="javascript">alert("phone number should be of 10 digit")</script>;'; } else { echo '<script language="javascript">alert("Please Enter valid phone number")</script>;'; } } … | |
Re: Look at line 21 of your code:[CODE]echo '</div>' [/CODE] You are missing the semi-colon at the end of the line, i.e. like this:[CODE]echo '</div>;' [/CODE] ![]() | |
Re: You cannot have multiple tags with the same id. Your code will output multiple instances of <input id="rate"> and <input id="qty">. You should serialise them, like this: [CODE]<?php include("config.php"); ?> <script type=text/javascript> function multiply(id){ var a; var b; var c; a = document.getElementById("rate" + id).value; b = document.getElementById("qty" + id).value; … | |
Re: This code does what you've asked, and starts looking from "tomorrow". [CODE]<?php $dt = new DateTime("tomorrow",new DateTimeZone("Pacific/Auckland")); $di = new DateInterval("P1D"); while ( ($dt -> format("l") != 'Tuesday') && ($dt -> format("l") != 'Saturday') ) { $dt -> add($di); } echo 'Next sale: '.$dt->format("l, j F Y"); ?>[/CODE] Just replace … | |
Re: AlmostBob's URL to the PHP site is fine, but his description is a bit off. Slashes and spaces are fine. It's nothing to do with the character set but in fact to do with characters reserved for HTML code. Imagine, for example that PHP_SELF contained a greater-than symbol like this: … | |
Re: Is your site one that people have to "sign in" to? If so, why not just build the consent into the standard terms and conditions that one must agree to in order to create an account? If it's a public site and does not require users to sign in, it's … | |
Re: If I can just chime in here.... Might just want to add a space after [B]Location:[/B] | |
Re: You can still use ErrorDocument in .htaccess to invoke a customised page for Error 403, and then in the custom Error 403 page you put at the top: [CODE]<?php header("HTTP/1.0 404 Not Found",true,404); ?> [/CODE] That will send the correct HTTP 404 response. | |
Re: Here's how you should be using the Date/Time features in PHP to achieve the same thing: [CODE]<?php $tz = new DateTimeZone('Europe/Paris'); $time = new DateTime("@1303889758",$tz); $time -> setTimeZone($tz); $convert = $time -> format("G:i:s d. n. Y. "); //convert $time to our date: output is 9:35:58 27. 4. 2011. echo $convert."<br>"; … | |
Re: I suspect it's that the setting "short_open_tag" is forced on, and so the first two characters of line 1 (the less-than symbol followed by the question mark) is causing PHP to start interpreting what is after that, which happens to be the contents of the XML header tag and not … | |
Re: Assuming your [I]allow_url_fopen[/I] setting is enabled (see [url]http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen[/url]) then here's the code: [CODE]<?php file_put_contents("/path/to/filename.html",file_get_contents("http://www.example.com/")); ?>[/CODE] | |
Re: Yes, there's always a risk that someone breaks into the server and steals your code. Not only do they now have your IP, but also potentially passwords (to databases) etc. You can encrypt your PHP code so that it's unreadable. Try [url]http://www.phpshadow.com[/url] | |
Re: [quote]strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'[/quote] The bit that's wrong is the use of single quotes instead of double quotes in HTML. The "span" tags should read: [CODE=html]<span style="font-size: 80%;"></span>[/CODE] | |
Re: Is the input the entire sentence, or just the name "Tim"? In the case of the latter, and aside from capitalisation, and assuming it's only the asterisk you ever want to replace, then use this: [CODE]$input = "Tim"; $pattern = "Hi my name is *"; $output = str_replace("*",$input,$pattern);[/CODE] Or is … | |
Re: [CODE]$low = "Low"; $int = "Intermediate"; $high = "High "; switch($perm) { case $low: echo "Low perm <br>"; break; case $int: echo "Intermediate perm <br>"; break; case $high: echo "High perm <br>"; break; default: echo "No information has been provided. "; }[/CODE] | |
Re: [CODE]$result = mysql_query("SELECT COUNT(*) FROM TEST Where Name LIKE 'Smith%'") or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row[0] ."; }[/CODE] | |
Re: Use this function: [CODE]function rmdir_recursive($dir) { $files = scandir($dir); foreach ($files as $file) { if ( ($file == ".") || ($file == "..") ) { continue; } $file = $dir . '/' . $file; if (is_dir($file)) { rmdir_recursive($file); rmdir($file); } else { unlink($file); } } rmdir($dir); }[/CODE] Call it like … | |
| |
Re: You need to put some debugging lines in to see where it's going back to login.php. There are two instances of header("login.php"). I suggest before each one you write some output (which will also prevent the redirect) so that you can identify which path your script is taking. Also line … | |
Re: IonCube is quite expensive! I would use the function get_included_files() to determine what was included. See [url]http://nz2.php.net/manual/en/function.get-included-files.php[/url] for more information. ![]() | |
Re: How about this for a one-liner: [CODE]echo preg_replace_callback('/<a ([^>]+)>([^<]*)<\/a>/m',create_function('$matches','return str_replace(" ","_",$matches[0]);'),$string);[/CODE] [B]BEFORE: [/B] Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in ante nec nisl vulputate faucibus at quis <a href="path/to/page" class="pageLink">felis</a>. Aliquam vel dui orci. Integer eget eros sed lorem vestibulum aliquet. Aliquam tortor lorem, semper et rutrum … | |
Re: The scope of ordinary variables outside a function remain outside that function. Conversely, the scope of ordinary variables inside a function remain inside that function. In other words, you cannot declare a variable outside a function and use it inside a function, without using the global keyword. So what you … ![]() | |
Re: Firstly, I should point out that not all email addresses are of the form something@letters.2-3letters. For example: [email]john@vuw.ac.nz[/email], [email]bob@blah.travel[/email], [email]fred@sprint.mobi[/email], and so on. I recommend you use this logic to determine the validity of an email address: [CODE]if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,})$/',$email)) { echo "Invalid address"; }[/CODE] Obviously you'll need to replace the … | |
Re: The only way I can think is like this: [CODE]$sql = "SELECT * FROM something WHERE id LIKE \"%,".$test.",%\" OR id LIKE \"".$test.",%\" OR id LIKE \"%,".$test."\"";[/CODE] | |
Re: [CODE]$sql = "SELECT COUNT(*) FROM tblName WHERE type=\"minor\""; $result = mysql_query($result); $row = msql_fetch_row($result); $number_of_minor_defects = $row[0]; $sql = "SELECT COUNT(*) FROM tblName WHERE type=\"major\""; $result = mysql_query($result); $row = msql_fetch_row($result); $number_of_major_defects = $row[0]; print "Minor defects: ".$number_of_minor_defects."<br>Major defects: ".$number_of_major_defects;[/CODE] Obviously alter the SQL code to suit your table structure … | |
Re: Err, don't think the code Will posted is entirely right. You need: [CODE]substr($_REQUEST['cc_number'] , -4)[/CODE] See [url]http://www.php.net/substr[/url] for more info and examples. | |
Re: [QUOTE=fatcat2010;1164372]hi experts, always curious . why sometimes reference book use simple quotation mark. sometime switch to double quotation mark. Does it matter in php? e.g. define ([COLOR="Red"]'[/COLOR]SQL_HOST[COLOR="Red"]'[/COLOR],'localahost'); however, in same define function i see double quotation in another source define([COLOR="Red"][COLOR="Red"]"[/COLOR][/COLOR]CONSTANT[COLOR="Red"]"[/COLOR], "Hello world."); Thanks.[/QUOTE] Most of the time it does not … |
The End.