Jump to content
php.lv forumi
Kristaps Arbm

Palīdzat uzlabot strpos

Recommended Posts

Sveiki... Tātad man ir kods kurš mani apmierinātu, bet ir problēma kad nepieciešami 2 un vairāk  vārdi.

 

Tie ir jāieraksta ar perfektu precizitāti. Man vajadzētu lai sakritība būtu arī  tad ja starp šiem 2 vārdiem ir 10 atstarpes.

 

$g = test test;
if (strpos   (($_POST['msg']), $g) !== false){
    echo "Sakrīt";
}
?>
Edited by Kristaps Arbm

Share this post


Link to post
Share on other sites

Noformulē vēlreiz un lēnām.

Edit; O, redzi, uzrakstot visu konkrētāk uzreiz ir risinājums. 

Edited by waplet

Share this post


Link to post
Share on other sites

Šādi derēs?

$g = "/test[\s]+test/";
$m = null;
$post = "mytest   tests";
if (preg_match($g, $post, $m)) {
	echo "sakrīt!\n";
}

Share this post


Link to post
Share on other sites

 

Šādi derēs?

$g = "/test[\s]+test/";
$m = null;
$post = "mytest   tests";
if (preg_match($g, $post, $m)) {
	echo "sakrīt!\n";
}

Ideāli varāk nekā es vēlējos.

Pirms tam mēģināju ar preg_match man nesanāca. Esmu vēl zaļš gurķītis php.

 

 P.S  Liels paldies Daudzsološais profiņš

Share this post


Link to post
Share on other sites

noteikti var arī šitā

$g = 'test test';
$post = 'test    	  test';
if (preg_replace('/\s{2,}/', ' ', trim($post)) === $g) {
	echo "sakrīt!\n";
}
Edited by indoom

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...