Results 1 to 4 of 4

Thread: Finding the text in URL with PHP.

  1. #1
    Join Date
    Nov 2008
    Posts
    162

    Finding the text in URL with PHP.

    Yesterday I was working on a script to validate reciprocal links directory redribera . The truth is that this is a utility which by default is implemented in most commercial scripts directory as phpLD or k-Links. However red ribera directory is a directory of his own making, and the functionality of the changes according to the requirements of maintenance. This is an advantage because it makes it very flexible to the needs that arise for me right administration. Clutchless the problem of its programming, which requires the knowledge of programming. Originally the board caught sending requests for links to the directory by using the links application form (to the right you can see a partial sample, where the field is highlighted to indicate the URL of reciprocal link). This information is provided by an applicant and stored in a database, where after an editor (myself) to conduct the review or approval.

  2. #2
    Join Date
    Nov 2008
    Posts
    162

    Re: Finding the text in URL with PHP.

    Like many folders, the long redribera began requiring a reciprocal link to validate an application. Is the minimum required to make the effort of editing applications and the inclusion in a directory already consolidated. However, the content of this field on the form was not validated by no means automatic, but after human review by an editor. To this day the number of applications that support the board is quite high, although most of them either did not indicate a URL where the reciprocal link, or in the URL provided there is nothing, having lost considerable time to perform the validation by the editor.

  3. #3
    Join Date
    Nov 2008
    Posts
    162

    Re: Finding the text in URL with PHP.

    So I spent some time in developing a php function that allows me to validate the existence of a text in a given URL (if any).
    Code:
    <? Php 
    
    
    validaLinkReciproco function ($ feedURL, $ searchString) { 
    / * Used to validate the reciprocal link. 
    Who use this script, probably by an include 
    Returns: true (string found), false (string not found) * / 
    
    / / First check if curl is installed on the web server. 
    $ CurlInstalled = true; 
    
    if (! extension_loaded ('curl')) { 
    if ( strtoupper ( substr (PHP_OS, 0, 3)) === 'WIN') { 
    if (! dl ('php_curl.dll')) {/ / Attempt to load the extension for Windows systems 
    $ CurlInstalled = false; 
    Else {} 
    $ CurlInstalled = true; 
    } 
    Else {} 
    if (! dl ('curl.so')) {/ / Attempt to load the extension for POSIX systems 
    $ CurlInstalled = false; 
    Else {} 
    $ CurlInstalled = true; 
    } 
    } 
    } 
    
    / / Depending on whether you installed curl, we obtain the data one way or another 
    if ($ curlInstalled == true) { 
    / / Retrieve data from curl 
    $ OhYeah = curl_init (); 
    curl_setopt ($ OhYeah, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ OhYeah, CURLOPT_URL, $ feedURL); 
    $ Err = curl_error ($ OhYeah) 
    $ Pagedata = curl_exec ($ OhYeah) 
    curl_close ($ OhYeah) 
    Else {} 
    $ Pagedata = file_get_contents ($ feedURL); 
    } 
    
    / / Find the string in the string 
    $ Pos = strpos ($ pagedata, $ searchString); 
    
    if ($ pos === false) { 
    / / String $ searchString $ feedURL not found in 
    return false; 
    } 
    else { 
    / / String $ searchString $ feedURL found in 
    return true; 
    } 
    } 
    ?>;
    This is obviously a function that should be used in the paragraph to validate the data submitted by the form, where $ feedURL, should contain the URL where you want to search (in our case given by the reciprocal link URL field - see the image above). The function returns true or false, depending on who is the search string in the HTML of the page listed for $ feedURL.

  4. #4
    Join Date
    Nov 2008
    Posts
    162

    Re: Finding the text in URL with PHP.

    This function is a generic, ie not looking for the existence of a reciprocal link in a URL, but any text so it can be reused for many uses that a webmaster wants to give. In our case, just look for the existence of the web link text, for example, $ searchString = "dominio.com", however it can force the searches much more, to validate the entire label and make sure for example that the applicant refers to our Web supply the exact text, thereby avoiding surprises like nofollow links, etc .... In my case, this simple addition to the directory prevents me reviewing a number of applications that do not comply with the policy of inclusion in the directory redribera. Of course, every law, a loophole, but I will leave that for another post ....

    I hope you can be useful to me as it has.

Similar Threads

  1. Finding replace text or symbol with carriage return in Excel
    By DEvOTeEL in forum MS Office Support
    Replies: 5
    Last Post: 23-02-2012, 12:19 PM
  2. Replies: 5
    Last Post: 28-02-2011, 08:23 PM
  3. BlackBerry Torch TEXT message icon not showing text messages
    By rOSAMOND in forum Portable Devices
    Replies: 8
    Last Post: 17-10-2010, 01:04 AM
  4. Replies: 5
    Last Post: 10-10-2010, 04:30 AM
  5. How to recover lost text from text area in Google Chrome?
    By Corwinn in forum Technology & Internet
    Replies: 5
    Last Post: 10-03-2010, 12:56 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,575,380.25745 seconds with 17 queries