asik
asik

Reputation: 15

how can I sort properly with preg_match?

I'm trying to modify a line in PHP file that deals with data that comes from XML(about 600 stations). The php make this data usable by a streamer media player. The original line is this

if (($title <> "")&& (strpos($link,"<") === false)&& preg_match("/Cha/i",$lang)) 

this gives me about 50 stations, I want to add few stations that do not have "Cha" in $lang but "Soprts" and has "China" in their $title.

So I wrote the line like this

if (($title <> "")&& (strpos($link,"<") === false)&& preg_match("/Cha/i",$lang)&& (preg_match("/China/i",$title)||preg_match("/Sports/i",$lang)))

But now I'm getting less results than before, now I'm getting only the stations that have CHA in $lang and "China" in $title. All the relevant stations that have CHA in $lang but not "China" in $title are ruled out.

As I have very limited knowledge in PHP I don't know how to make the proper sorting, someone offered me to use stripos but I don't know how to use it and his example didn't worked OK

Upvotes: 0

Views: 177

Answers (2)

Lola
Lola

Reputation: 1908

You flipped the and and or in your new code. You want:

if (($title <> "")&& (strpos($link,"<") === false)&& (preg_match("/Cha/i",$lang)|| (preg_match("/China/i",$title)&&preg_match("/Sports/i",$lang))))

Upvotes: 1

safarov
safarov

Reputation: 7804

You dont put bracets corretly. You can add multiple options in regex by using | (means OR) ,try this:

if (($title <> "") && (strpos($link,"<") === false) && preg_match("/CHA|China|Sports/i",$lang))

Upvotes: 0

Related Questions