-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
No matter what file function you use PHP has no context of the file you are reading. It just returns whatever is in the file. It does not know you only want the text from the html file. You could use a function called stip_tags which can remove HTML from the line you have read from the file. But a better way would be to parse the HTML DOM and then only return the node value(s) to get the plain text from the html file. When is the password submitted? After the radio button has been submitted? If that is the case then you will need to either the add the value of $filename to a hidden input field or add it to a session variable in order for that value to remembered when the password form has been submitted.
-
That will be why my code is not working as expected. You did not mention that earlier As I said earlier all files (including the php file) need to all in the same directory in order for it work correctly. Code updated if (isset($_POST['submitradio'])) { $selected_file = $_POST['radio1']; // get the filename of the file $fileinfo = pathinfo($selected_file); $filename = $fileinfo['dirname'] . DIRECTORY_SEPARATOR . $fileinfo['filename']; // check to see if a html file named the same also exists if(file_exists("$filename.html")) { echo "$filename.html shares the same name as $selected_file"; } else { echo "Could not find a html file that shares the same name as $filename.html"; } } Should work as expected this time.
-
Yes. I have tested my code and it functions correctly. This is the form I am using to test with and I only have an order.html file in the same directory as the php code <form method="post"> <input type="radio" name="radio1" value="order.gif" /> Order<br /> <input type="radio" name="radio1" value="dummy.gif" /> Dummy<br /> <input type="submit" name="submitradio" /> </form> Selecting the Order radio button I get "order.html shares the same name as order.gif" Selecting Dummy radio button I get "Could not find a html file that shares the same dummy". Maybe the data in your form is different. What is the output of the following printf('<pre>%s</pre>', print_r($_POST, 1));
-
Need Drop down menu to display information based on username
Ch0cu3r replied to phunnydoode's topic in PHP Coding Help
In your edit code you need to apply a WHERE clause to the query so it only returns the row where username matches. Eg $query = "SELECT * FROM `bencobricks` . `users` WHERE username = '$username'"; However you should not use user input in a query like this. Instead I recommend you to use prepared statements. -
Thats is what my code does. All you need to do is change the echo statements to what you want to output when a filename match is/not found. For my code to work correctly the .gif and .html files need to be in the same directory as where this code is being ran. If the files are in a different directory then you need to tell us.
-
Not sure what you are asking but maybe... use file_exists to see if a html file shares the same name as the image. if (isset($_POST['submitradio'])) { $selected_dir = $_POST['radio1']; echo '<img src="'.$selected_dir.'" />'; // get the filename of the file $filename = pathinfo($selected_dir, PATHINFO_FILENAME); // check to see if a html file named the same also exists if(file_exists("$filename.html")) { echo "$filename.html shares the same name as $selected_dir"; } else { echo "Could not find a html file that shares the same $filename"; } }
-
a for loop that fetches several fields by ajax from database
Ch0cu3r replied to amirreza99's topic in PHP Coding Help
Ok, So you after an infinite scroll effect, whereby new content is loaded automatically when the user scrolls to the end of the page/html element. Basically in your PHP code you want to first implement a technique called pagination, but instead of outputting all the links to each page you only output the link for the next page. Now using javascript when you detect the user has scrolled to the bottom of the page, you then look for the link for the next page and get its url. Once you have the url you would do an ajax request to get the next page data from that url and append its contents to the current page. And so the overall effect will look like the content is continually scrolling. Couple of tutorials I found http://www.1stwebdesigner.com/infinite-scrolling-tutorial/ http://www.w3bees.com/2013/09/jquery-infinite-scroll-with-php-mysql.html You can find more by goggling terms such as "PHP Pagination inifante scroll" "Javascript infinite scroll" etc. -
Best practice for outputting HTML from within PHP
Ch0cu3r replied to enveetee's topic in PHP Coding Help
Thats the approach I would use. Your HTML output should be separate from your business logic (the code that processes the request). However instead of file_get_contents I would use include so then I could still use PHP variables within the template file. -
a for loop that fetches several fields by ajax from database
Ch0cu3r replied to amirreza99's topic in PHP Coding Help
This will cause an infinity loop. The condition $print=$printed+3; will always return TRUE. Maybe you meant $print<=$printed; for ($print=$printed; $print=$printed+3; $print++) I fail to see why you need the for loop. Because even if you did construct the loop correctly it you will find you'll get duplicate results being returned. Is the purpose of the loop to limit how many results are returned from your query? If so then you should use the LIMIT clause -
Did you click the link? It explains it all in there.
-
You need apply delimiters to your regex pattern
-
Protecting your code on a 3rd party server?
Ch0cu3r replied to enveetee's topic in PHP Installation and Configuration
Short answer not really. As PHP is not a compiled language all code is in plain text format. Your options are to to use a software license agreement (EULA) to protect your assets (up to you how you enforce it). Or you could use an encoder which obfuscates your code, making it harder for the end user from reading your source code. -
using $variable = function() { RETURN 'HELLO WORLD'; }
Ch0cu3r replied to Monkuar's topic in PHP Coding Help
Nope The first block of code uses ternary operator (aka inline if/else statement) and a if statement. Second block of code uses an anonymous function. None of which features object oriented programming. Why would that matter? You will not be able to notices the differences between the two. object orientated programming in javascript is not the same as object orientated programming in PHP. -
Unless @whatever will always at the end of your your subject string (nothing comes after it) you could use the $ (end) anchor to get the first match from the end of the subject string. $text = '@Nexus @Cupcake @George'; $text = preg_replace_callback( "/(@[a-zA-Z-0-9]+)$/" , "umentions", $text, 1); The fourth argument is only used to limit how many replacements can take place. It cannot be used to change the order of the matches. The alternative way would be use preg_match_all to find all the matches then use end on the array of matches that was returned to get the last match.
-
preg_replace one or more sets of letters between brackets
Ch0cu3r replied to dde's topic in Regex Help
The regex ([2-9TJQKA][hdcs]\s?)+ is finding the two character codes within the square brackets The reason for the ? is to match whether or not a (white)space character comes after the two character code. As each code is separated by a space, except the last code. The + is so it matches all the two character codes followed by the optional space character within the square brackets. Without it, only the first two character code will be found. See the differences yourself by adding and removing the ? or + from the regex pattern here http://regexr.com/3a8gu -
preg_replace one or more sets of letters between brackets
Ch0cu3r replied to dde's topic in Regex Help
Try $text = 'Another example: [2d 2s 2h], or [3s 4h 5c]'; // find the codes within the square brackets // pass the matches to a callback function to replace the codes with images $text = preg_replace_callback('/\[(([2-9TJQKA][hdcs]\s?)+)\]/', function($m) { // separate the codes between spaces $codes = explode(' ', $m[1]); $html = ''; // loop over each code and replace it with the corresonding an image foreach ($codes as $code) { $html .= '<img src="/images/'.$code.'.png">'; } // return the images return $html; }, $text); echo $text; -
I have no idea what you are asking. But I can tell you are using session_start() incorrectly. It should only used before any output, this includes code that is outside of the php tags too. NOTE: When posting code please wrap it within tags or click the <> button in the editor. I have edited your post for you.
-
When you say Java do you mean JavaScript? As they totally different languages.
-
You would use mod_rewrite for this. Have the following in a .htaccess file in your sites document root. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([\w]+)?$ index.php?profile=$1 Then output your links in the new format, eg $username = 'Nathan'; // users username echo '<a href="/'.$username.'">'.$username.'</a>'; // output link in the new format
-
Make sure you are accessing http://localhost to run your .php files. Loading them directly into your web browser (the address bar starts with file://) will not work.
-
$i++ increments the value after the (assignment) operation has occurred, not during the (assignment) operation. For that you need to use ++$i But there is no need to do $i = $i++; just do $i++;
-
installing linux on a netbook without any dvd-drive - doable?
Ch0cu3r replied to Maze's topic in Miscellaneous
Alternatively you could get an external dvd drive.