Im trying to create a function to check for a substring within a string in php.
public static function stringCheck ($string, $substring) {
$patern = "/".$substring."/";
if (preg_match($substring, string) {
return true;
}
else return false;
}
but if i enter a special character used in preg_match (^.[$()|*+?{) it screws up ...
Hi all,
I am in the following situation. I am trying to convert a messy scraped html code to a nice and neat xml structure.
A partial HTML code of the scraped website:
<p><span class='one'>week number</span></p>
<p><span class='two'>day of the week</span></p>
<table class='spreadsheet'>
table data
</table>
<p><span class='two'>anoth...
I have a couple hundred single words that are identified in a foreach routine and pushed into an array.
I would like to check each one (word) to see if it exists in an existing txt file that is single column 200k+ lines.
(Similar to a huge "bad word" routine i guess but, in the end this will add to the "filter" file.)
I don't know whe...
I am writing a PHP script that accepts a regular expression pattern from the user which is used by preg_match(). How can I check that the pattern is valid?
...
Incoming is a single word from a text box or another function
function searchformatch($keyword){
if(!$keyword){hey-enter-a-keyword-function();}
foreach (glob("directory/*.txt") as $filename) {
$file = $filename;
$contents = file($file);
$string = implode($...
I am trying to match a Youtube URL with regex to see if it is valid. This is my code:
if(preg_match('\bhttp://youtube.com/watch\?v=.*\b', $link))
{
echo "matched youtube";
}
But I'm getting an error:
Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\ajax\youtube.php o...
How do I make the expression which checks the birthday input to match a format like this dd/mm/yyyy? Below is what I came out so far, but it takes this too if I put 99/99/9999!
if (!preg_match("/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/", $cnt_birthday))
{
$error = true;
echo '<error elementid="cnt_birthday" message="BIRTHDAY - Only this bi...
how can i create a preg_match_all regex pattern for php to give me this code?
<td class="class2"> </td>
<td class="class2" align="right"><span class="DarkText">I WANT THIS TEXT</span></td>
To get me the text inside the span class?
thanks!
...
Content of 1.txt:
Image" href="images/product_images/original_images/9961_1.jpg" rel="disable-zoom:false; disable-expand: false"><img src="im
Code that does not work:
<?php
$pattern = '/(images\/product_images\/original_images\/)(.*)(\.jpg)/i';
$result = file_get_contents("1.txt");
preg_match($pattern,$result,$match);
echo "<h3>Preg...
Hello,
I am trying to write a function to just get the users profile id or username from Facebook. They enter there url into a form then I'm trying to figure out if it's a Facebook profile page or other page. The problem is that if they enter an app page or other page that has a subdomain I would like to ignore that request.
Right now...
hello!
i find regex kinda confusing so i got stuck with this problem:
i need to insert <b> tags on certain keywords in a given text. problem is that if the keyword is within the href attribute, it would result to a broken link.
the code goes like this:
$text = preg_replace('/(\b'.$keyword.'\b)/i','<b>\1</b>',$text);
so for cases li...
I'm trying to match letters C D F H I E1 E2 CR (case insensitive) and came up with this. It'll match a single letter but wont match the E1 E2 CR. Actually it should. Whats the right way to do this?
preg_match('/^([C]|[D]|[F]|[H]|[I]|[E1]|[E2]|[CR]?)$/','CR')
...
Hello guys.
Please help with this little issue if you could.
I would like to search a string, if a match is made, I'd like to change the value to something else.
eg.
if (preg_match("gmail",$email)) {
// code needed to switch "gmail" for "googlemail"
}
This is needed because my mail server won't accept an email address in 'gmail...
I am trying to parse text for email id's using php / regex. Are there any classes or built in methods to do this?
The text contains multiple email id's at random places.
The source of the text is .doc files, which I then copy paste into forms, to be processed on submit.
preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $email) //from ...
Hi,
How do I write a regular expression which matches number-alphabets and commas only?
I came out with this one below but it doesnt work - it accepts other punctuation marks as well!
# check for matches number-alphabets and commas only
if(!preg_match('/([a-zA-Z0-9]|[a-zA-Z0-9\,])/', $cst_value))
{
$error = true;
echo '<erro...
Hello,
I have a problem with preg_match_all.
While preg_match does reply the whole match as the first element of the array, preg_match_all doesn't - the first array is empty.
At least with the pattern I chose (havn't tried others since it's the one I need) it doesn't work.
Here is my code:
preg_match_all("/<\?\?(\t| )?translate(\t| )?...
I'm wondering a good way of splitting strings by a | delimiter if the input strings could be of the following form:
"foo, bar"
"foo ,bar"
"foo,bar"
"foo , bar"
"foo bar"
"foo,,bar"
So the only possible outputs strings are as:
"foo|bar"
"foo|bar|other|here"
Independently of how many terms are within the input string.
Any t...
Hi Guys,
I need a regular expression to capture field names listed in a string. They are listed between
Here are my requirements:
field names in curly braces
field names have no spaces
curly braces can be escaped with a \
So in the following:
capture {this} text and exclude \{that}?
The matches are {this} but not {that}.
I'm us...
Hi, I have been trying to get this regex work. Suppose to parse an URL, if the string '_skipThis' is found, don't match the string. Also backreferences are needed too. For example:
String 1: a_particular_part_of_string/a/b/c/d/e/f
Result: preg_match should return true
Backreference: $1 -> a_particular_part_of_string, $2 -> /a/b/c/d/e/f
...
if (preg_match('^'.preg_quote($this->config_document_root), $filename)) {
$AbsoluteFilename = $filename;
$this->DebugMessage('ResolveFilenameToAbsolute() NOT prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")', __FILE...