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;
?>
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 have big problem. I have some code like :
This is in my folder "country"
if($_GET[''] == 'England') {
echo 'test';
}
Is that impossible to left empty get parameter? to get url like : link.com/country/England
You can do the following: example.com/country/?England, and check if the England key exists:
if(isset($_GET['England'])) {
// Do stuff
}
Without the ? characters, it's a bit more difficult and require to rewrite URL with [mod_rewrite][1] if you're using Apache web server for example
You are looking for url rewriting: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
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 this link viewdocument.php?a=http%3A%2F%2Fwww.iesalfonsox.com%2Fimages%2FLIBROS_ESO_13-14.pdf in (for example) index.php and I want to put only the URL of the document of the link.
Example:
Link: http://www.myweb.com/viewdocument.php?a=some.pdf
On the HTML: You're viewing "Some.pdf".
Do you understand? Convert "viewdocument.php?a=some.pdf" to "some.pdf".
If this is the current URL being accessed on your site, Php provide globals and you can access it using the $_GET variable:
so for your example you will use this:
$file = $_GET['a']; // will return some.pdf
The other case will be for parsing a url from a string, for which php provides a function:
parse_url();
Follow the link to see examples
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
It's a blank page and that's not how it's supposed to be :/
Can anyone help me out with this?
Code - http://pastie.org/private/9klk5tm6goixq4ev93tkq
-
Mord
You need closing parenthesis on every line that has one opening.
Example:
move_uploaded_file($_FILES["thematicseniorphoto"]["tmp_name"], "uploads/" . $_FILES["thematicseniorphoto"]["tmp_name"];
should be
move_uploaded_file($_FILES["thematicseniorphoto"]["tmp_name"], "uploads/" . $_FILES["thematicseniorphoto"]["tmp_name"]);
EDIT:
Next time use a while() statement and find a pattern of text to search/use. You'll go from 700 lines to like...20.
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 suck at regexp but i'd like to just do a simple filter where / is replaced with 1, " is replaced with 2 and < is replaced with 3.
I'd appreciate an example where the syntax would be straight forward, i'd like to run this filter through the input of a get variable provided by the user. A syntax like:
replace(/,1)
replace(",2)
replace(<,3)
.
Thanks.
I really don't see the need for regex here.. You can just use str_replace
E.g.
str_replace('/', '1', $_GET['var']);
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 text like this Too early to post? http://www.somewebsite.com/article/226973 I want to parse the hyperlinks in the text and make the text look like so Too early to post? http://www.entrepreneur.com/article/226973 I want to do this but I have no idea where to start from or what regexp to use.
$s = 'Too early to post? https://www.somewebsite.com/article/226973';
$parsed = preg_replace('#(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)#', '$1', $s);
echo $parsed;