Folks,
Building rough Searchengine.
Need to echo user submitted links on SERPs. Prolem is, different links will be in different php format. How to auto detect the format ?
Q1. Since my searchengine will be opening the iFrame (of user submitted links) to other users (keyword searchers). How will I know on auto which part of the url to run htmlentities() and which parts to run the urlencode() ?
I can’t be manually checking the url /link format on a million link each day that my users submit to me everyday.
I mean, if I was opening an iFrame to my own link then no problemo as I know my own link’s format:
Example:
(printf code from NogDog):
““
$url = ‘http://localhost/test/pagination.php’;
$search = $domain;
$tbl = ‘linking_histories’;
$col= ‘domain’;
$i = 1;
$limit = 2;
printf(
“<iframe src=’%s?mysql_tbl=%s&mysql_column=%s&keyword_search=%s&result_limit_per_page=%d&page_number=%d’></iframe><br>”,
htmlentities($url),
urlencode($tbl),
urlencode($col),
urlencode($search),
$limit, // %d place-holder will force integer
$i, // ditto
urlencode($limit),
urlencode($i)
);
I mean, a user might submit a normal static link like so:
A.
““
‘http://localhost/test/pagination.php’;
Or, a dynamic one, like these:
B.
““
‘http://localhost/test/pagination.php?keyword=cars’; //%s (printf).
C.
““
‘http://localhost/test/pagination.php?page=4’; //%d (printf).
D.
““
‘http://localhost/test/pagination.php?keyword=cars&page=4’; //%s (printf) & %d (printf).
For the example A submitted link, this php code is correct to echo the url in the iFrame:
““
$url = ‘http://localhost/test/pagination.php’;
printf(
“<iframe src=’%s’></iframe><br>”,
htmlentities($url),
);
For the example B submitted link, this particular php code is correct to echo the url in the iFrame:
““
$url = ‘http://localhost/test/pagination.php’;
$search = $domain;
printf(
“<iframe src=’%s?keyword_search=%s’></iframe><br>”,
htmlentities($url),
urlencode($search),
);
For the example C submitted link, this particular php code is correct to echo the url in the iFrame:
““
$url = ‘http://localhost/test/pagination.php’;
$i = 1;
printf(
“<iframe src=’%s?page_number=%d’></iframe><br>”,
htmlentities($url),
$i, // ditto
urlencode($i)
);
For the example D submitted link, this particular php code is correct to echo the url in the iFrame:
““
$url = ‘http://localhost/test/pagination.php’;
$search = $domain;
$i = 1;
printf(
“<iframe src=’%s?mysql_tbl=%s&mysql_column=%s&keyword_search=%s&page_number=%d’></iframe><br>”,
htmlentities($url),
urlencode($search),
$i, // ditto
urlencode($i)
);
As you can see from above, the 4 links on the 4 iframes are not same url format.
One uses just htmlentities() and no urlencode(),
another uses the htmentities() plus one urlencode() ONLY
while another uses the htmlentities() and TWO urlencode()
and so on.
Some links have INT while others don’t.
Now since each user submitted link will be different to each other, then I can’t use one set of printf to echo all url formats.
So how to detect the url format on auto to generate the right printf with the right data type on the printf (eg. ‘%s’, ‘%d”) for that particular url the user submits ?
Is there any function in php that can detect the url type to tell me which functions (htmlentities, urlencode(), %s, %d, etc. to use on which part of the url ? You know the var_dump() tells you the data type. Something like that I am looking for.
Q3.
What’s ‘ditto’ that you put on following ?
““
$i, // ditto.