Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
My PHP scripy receive a string from JS. And i need to parse it to ignore the resolution suffix the image come with, but preserve the filename.
More clearly:
I need to transform this string: starbucks-logo-291x300.jpg into starbucks-logo.jpg in PHP. But sometimes the filename may have a longer string name, like starbucks-logo-2921x3030.jpg and starbucks-logo-291x3200.jpg.The filename prefix may change, so i cant't make it search for "starbucks-logo". Sometimes the filename have no suffix, and come just as i need. And sometimes the file may come in another image extension, like png, gif, jpeg, and bmp.
I'm new to php, so if possible, be clear about the function i need to use, please <3
This can easily be done:
$result = preg_replace('~-\d+x\d+~', '', $filename);
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just received a source from my customer (it's written by PHP Generally), I try to read it and glance at database. I realize that it's very mess, some webpage's content is also saved in database. So, I want to find files are using by browser and I mean that php files, I want to edit them. Can I do that?
P/S: I'm sorry if this article bother you
Hi At any point you need to know what functions, what includes and what arguments are being passed just use debug_print_backtrace() function in your code.
for further reading follow http://www.php.net/manual/en/function.debug-print-backtrace.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need a php code that will be able to remove only a specific part of a url for ex this type of url:
http://www.website.com/wp-content/uploads/2013/10/picture-242x300.jpg
To remove only the the first seven characters after the "-" and also to be removed "-"
So the final output would be
http://www.website.com/wp-content/uploads/2013/10/picture.jpg
Where the extension would be at the end .jpg, .gif or .png
The correct code is
$image = preg_replace("#-[0-9a-z]+.(jpe?g|gif|png)#i",".$1$2",$image);
Try:
$url = preg_replace("#-[0-9a-z]+\.(jpe?g|gif|png)$#i","\\1",$url);
Take a look at the preg_replace() documentation.
<?php
$string='http://www.website.com/wp-content/uploads/2013/10/picture-242x300.jpg';
$s=preg_replace('/[-]\d*x\d*/','',$string);
echo $s;
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my project I use php and yii framework.
I have a predefined set of the disallowed html tags(for example - "script, object") and I need to check that entered text don't contain any of these tags.
What function I can use in order to do that ?
If you're dealing with potentially unsafe HTML from the client (WYSIWYG editors etc.), I'd use a library like HTML Purifier. It lets you to specify allowed and disallowed tags.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to read a file, but it keeps printing all of the data to the page without my asking it to do so.
The code is:
<?php
$htmlAppointmentPage = readfile('AppointmentPageTemplate.html');
?>
That's all of the code. For some reason it's echoing the contents of AppointmentPageTemplate.html.
You want file_get_contents() and not readfile().
From the Manual:
This function is similar to file(), except that file_get_contents()
returns the file in a string, starting at the specified offset up to
maxlen bytes. On failure, file_get_contents() will return FALSE.
file_get_contents() is the preferred way to read the contents of a
file into a string. It will use memory mapping techniques if supported
by your OS to enhance performance.
Please note that if your file is very large, it would take a lot of memory (= the file's size) to place it into a variable. Make sure you don't go over the limit set in php.ini.
readfile reads the contents of a file and outputs them to the page.
To get the contents of a file as string (and assign them to a variable), use file_get_contents
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a folder which contains several html files: 1.html, 2.html, 3.html, etc., etc. in sequential order.
I would like for PHP to randomly load in these files into a PHP webpage that I have. How can I go about doing this?
Also -- is PHP the most efficient way to do this? Would jQuery be better?
jquery could do it, but you'd have to send a list of the available files to the client beforehand, so it has a list to choose from. This would be required if you can't guaranteed there'll never be "holes" in the files, e.g. 1,2,4,5 (hey, where's 3?).
PHP can deal with the raw filesystem, and can always get the list of files, e.g.
<?php
$files = glob('*.html');
$random_file = $files[array_rand($files)];
include($random_file);
This will handle any .html file, regardless of holes in the numbering sequence, or even if they're numbered at all.