Skip to content
Advertisement

Tag: regex

.htaccess remove URL path segments that are causing an Internal Server Error

The following .htaccess Rewrite below seems working fine if the URL is something like: example.com/news/post-1 However, if the URLs have more parameters, something like: example.com/news/post-1/comment-page-1 (URLs from another version of the website) I will get a 500 Internal Server Error. How I can make it redirect to the related post instead of 500 Internal Server Error? Answer if the URLs

htaccess – Deny access to pdf files in folders

The goal is to restrict direct browser access to all *.pdf various subfolders within a main folder. The subfolder names in which each pdf file reside are numeric only (characters 0-9; Eg. “work/books/112/myfile.pdf”) What I have so far is: RewriteRule ^work/books/([0-9]+)/.pdf)$ [F,L,NC] Where ‘books’ is my main folder and then whatever numeric folders in which pdf files reside, there are.

Getting zipcode from a string

I am trying to get zipcodes out of address strings. Zipcodes may look like this: 23-123 or 50-530. Strings usually look like this: Street 50, 50-123 City What I tried to do is finding the position of the zipcode and cut the next 6 characters starting from that point. Unfortunatelly strpos returns false all the time. Answer The strpos does

How to remove specific html tags with contents in php?

I have some contents in string format include some unwanted html tags and its content. I am looking for a way to remove them but still could not find a perfect solution for the purpose. Method 1 Normally, we use strip_tags to remove the tags but it reserves the text content inside the tag. Method 2 Then I tried to

How can i replace all specific strings in a long text which have dynamic number in between?

I am trying to replace strings contains specific string including a dynamic number in between. I tried preg_match_all but it give me NULL value Here is what i am actually looking for with all details: In my long text there are values which contains this [_wc_acof_(some dynamic number)] , i.e: [_wc_acof_6] i want to convert them to $postmeta[‘_wc_acof_14’][0] This can

(REGEX) Replace with empty when two appear in a string PHP

i have differents strings may be can: 1 Case 2 Case 3 Case I’m try to limit to In cases if have found 3 or more continue With the php code: Expected cases: 1 Case 2 Case 3 Case Used regex: Testing: https://paiza.io/projects/sLcZE5fW99p3gfrxaZGDsg Thanks My Regex not working Answer If you want to replace three or more <br> tags with

regex skip match if its follows by whitespace and a keyword

Currently trying to match comments with regexes but only if no function follows. Currently I use a regex which also matches the keyword function. And then check in the source code (php) if this group is set or not. https://regex101.com/r/l0j1ip/1 Now the question is whether it is possible to realize with pure regex. I have tried it with a simple

RegEx not matching all required chars. What did I do wrong?

I want to allow inputs like _X_C or _X_X_X with the following regex: The following should be allowed only once: _X_C _X_L _L or … _X_X_X (0 to threetimes) The only thing that does not work is the allowance of “_X_X_X” or even “_X” What did I do wrong? Answer You may use See the regex demo. Details: ^ –

How to get price value with regular expressions

I am trying to write a crawler for an Online Store and now I need to get the price value of the webpage. Here is my try: Basically $html holds the source code of the webpage and the price value is stored at the document like this: <div class=”c-product__seller-price-pure js-price-value”>10,699,000</div> But when I run this I get this as result:

How to get specific (unique code) word from string on php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have text string like : [CLOSED][#SD_1623834126_001] lorem ipsum ? and question is, how I get unique code/my ticket number #SD_xxxx

Advertisement