Forum Moderators: coopster

Message Too Old, No Replies

match a string even if its broker

         

Anyango

8:28 am on Jul 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SORRY: The Subject is "match a string even if its broken
", i mistanely typed "broker"

----------------------------

in this case

"This is a string"

and

"This is a

string"

should return true if matched for equality

the actual problem is, that there is a small search and replace function in our code right, it takes a keyword and replaces it with other, but sometimes if you create sites in dreamweaver it disturbs the code like this

<p>this is test
keyword in a paragraph</p>

now if when i search for "test keyword" it is not being found because of that endline character and spaces, i tried to remove \n but no good, is there any way so that if we search for something in a string, it returns true even if there are whiespaces or tabs or newline characters between it?

like

$string1="<p>this is test keyword in a paragraph</p>";

$string2="<p>this is test
keyword in a paragraph</p>";

should return true if i find "test keyword" in those strings

findString($string1,"test keyword"); should be equal to
findString($string2,"test keyword")

Thanks

jd01

8:16 pm on Jul 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Anyango,

I forgot to read all the way through your post - I think you will need to switch from a simple match to a regular expression match.

Adding the 'm' multi line modifer should match the phrase across multiple lines.

See: [us2.php.net...]

You could also add a 0 or more spaces/space characters with \s* and then adding the U modifier to keep the greediness of your expression in control.

Hope this helps.

Justin