Skip to content
Advertisement

Tag: regex

preg_replace get each two characters from a word

Actually I’m trying to come up with a way of getting a string like “GEWO” out of the “Get Word” by using preg_replace function. The thing is there also can be a strings like “Get”, or “Get Word And another Word” so I have to get the proper string respectively. Thanks! Answer Use this: ouput: GEWOANANWO

preg_match accented characters

I have an issue using preg_match with php. I want my users to fill the Name field with only valid characters. Ex: no numbers or special chars. My site will eventually be bilingual but most of my visitors are french Canadians I prefer utf-8 for my encoding. So at the top of my document i have this tag : I

Correct way to add comments to a Regular Expression in PHP

I’m trying to add comments to make a regexp clearer But i get the warning Warning: preg_replace(): Unknown modifier ‘/’ in on line 280 How should i comment it? Answer This may not be the cleanest approach, but you could enclose each section in quotes and concatenate them. Something like this should work: Alternatively I found this in PHP docs.

PHP – Why am I being warned that my regular expression is too large?

I would like to use a regular expression to validate user input. I want to allow any combination of letters, numbers, spaces, commas, apostrophes, periods, exclamation marks, and question marks, but I also want to limit the input to 4000 characters. I have come up with the following regular expression to achieve this: /^([a-z]|[0-9]| |,|’|.|!|?){1,4000}$/i. However, when I attempt to

Preg_match string inside curly braces tags

I’d like to grab a string between tags. My tags will be with curly braces. So far I have found #<s*?$tagnameb[^>]*>(.*?)</$tagnameb[^>]*>#s This one matches tags with angle brackets <>. I couldn’t figure out how to make it look for curly braces. Eventually I would like to parse whole page and grab all matches and build an array with strings. This

How to replace custom html tag with html code in php

This is my scenario: In a custom CMS developed in PHP, I need to parse HTML string searching some custom tags to replace them with some HTML code. Here is an example for clarifying: I need to find the custom tags and replace them with the template of the item, as a result: This would be very helpful, but I

Advertisement