Jump to content

string.search working incorrectly


Volte

Recommended Posts

Hey, pulled some info from my page, only, when I search for a specific string, it cant find it, I keep chopping characters off the end of the string that I am searching for, and it takes me up to this:

[code]data.search("<a href=\"/tvpdb?")[/code]
Any other characters after this (even when I know for a fact they DO exist) returns -1 (I "alerted" the results of the search, -1 means it wasn't found).

The string is part of a url, and I'm actually searching for this entire part, but it will not cooperate:

[code]data.search("<a href=\"/tvpdb?d=tvs&id=")[/code]
Any tips, insights, ideas, solutions?

Thanks a lot
Link to comment
https://forums.phpfreaks.com/topic/8527-stringsearch-working-incorrectly/
Share on other sites

Pop this:
[code]<div class="chan">
<h2><a href="/tvpdb?d=tvs&id=166030801&channels=us_KTVU&lineup=us_CA04931d&.intl=us">FOX<br>2</a></h2>
<h2 class="right"><a href="/tvpdb?d=tvs&id=166030801&channels=us_KTVU&lineup=us_CA04931d&.intl=us">FOX<br>2</a></h2>
<ul class="chan">[/code]

Into a variable, and then try and do:

[code]alert([the variable you put it into].search("<a href=\"tvpdb?d="));[/code]
and then do:

[code]alert([the variable you put it into].search("<a href=\"tvpdb?"));[/code]
and watch the results. Look closely at those last two lines of code. Boggles my mind why it wont work.

EDIT: Ok I think I narrowed it down to the "?", but why? and how do I overcome this. Any solutions? I've tried escaping it of course: "\?" but that doesnt help. >.< Grrr.
Ok, thanks for the explains,, it's now more clear to me, about the 'search' function, (I usually parse in php,...)

Try that one,,
-----
data.search("<a href=\"/tvpdb[b]\\[/b]?d=tvs");
-----
It should do the job,, ;)

"?" is a magic/special character,, & it seems we need to add 2 "\" to include it,...

Hoping it helps,,

l8tr,,

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.