scbookz Posted July 30, 2009 Share Posted July 30, 2009 where do i put a new function thatmy code can grab automatically and how do i link them? do i put the new function in the directory that my items are in or do i point the code to the directory? mysql php5 apache2 ubuntu thanks Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 Do you mean you create function or functions to somefile and then you want to use these in other php files? If so.. functions.php <?php function myFunction() { // do somthing } Then in other files you want to use this / these functions.. just include the functions file before using. <?php include('path/to/functions.php'); Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 30, 2009 Author Share Posted July 30, 2009 i was hoping i could have the function called with no path where it is with allthe other functions that php uses in other words i want to be able to run a program and this function is automatic as with any other php base function Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted July 30, 2009 Share Posted July 30, 2009 you are going to have to be more specific than that. in Tendolla's example, you can put a common function in one file, and then include that file in all of your other pages so you can use the same function on all of the pages without having to explicitly code it on each page. you are really not explaining what you want very well though Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 If you mean something like php's autloading for classes that is not possible with functions. Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 ok here is what i mean in bash i can add functions and linux will execute them no matter where i am on the server if you use the echo command it is built into php i have a function i need to use for 10,000 web pages i need to refer to that function instead of having the code on every page i would like to have it work as if it is any other command any time i need it as with the echo or any php built in function in other words the code will look for that function as if it is built into the php code Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 here is my function i need 10000 pages to pull from this with different links ----------------------- // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all('/<title>(.*)<\/title>/', $file, $matches, PREG_PATTERN_ORDER); return($matches[1][0]);} ----------------------------------------------- Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 anyway thanks for the help i guess i would have to recompile php if it was even possible no idea Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 31, 2009 Share Posted July 31, 2009 I am not sure if I am following you now... but phps built in functions are php syntax and I think that they are coded in C. So there is no way (atleast that I Know) you could insert own function in php's syntax. If the case is that you have 10000 php files where you want to use your function I guess you just have to include it to all these files or create some script that will add the include line to all files needed. Or do you want to pull the title from 10000 different websites? If this is the case then you must have stored somewhere all these sites. And you can loop through the sites and inside that loop call your function for each site and store the titles in array for example. Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 right now we are getting into the details of what i am doing i am pulling titles from html pages only but the page will correspond to the isbn of a book so each page i pull the title from will be based on http://www......com/1234567890 i am pulling a tag only and each 1234567890 number corresponds to the data sheet i upload as i upload my spreadsheet i use php code in a cell and the code in the cell works for a small line of code if i add the function to the cell it wont work so............... i am trying to use as little code in each cell as possible so i think i will do as you say wget every page to my server and then figure something out it is possible i could grab the titles to the data base 1st and then use less code but i am not sure as ofyet i bulk upload 1000 books each upload and my .jpg files are attached automatically and now i just need titles and i am done it works i have one page done but i am trying to make it as short of code for each book as i can anyway i will see how it turns out soon enough i figure 1 more week before i am online with my pages Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 31, 2009 Share Posted July 31, 2009 You don't need to necessarily wget the page contents. You can do this also with php as long as you just know the urls of the sites. Just found this on google, might be worth checking.. http://www.drquincy.com/blog/get-remote-web-page-info-with-php/ . Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 right i have the function to get the tags but the delima is uploading the code via excel spreadsheet cells to my database ------------------------------- <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); $file = file_get_contents("http://www.xxxxxxxxxxxxxxxx.com/isbn=0324183313"); $x = (get_doc_title($file)); echo preg_replace('/^bbbbbbb-/','(10 digit isbn above) -',$x); // retrieve page title function get_doc_title($file){ $h1tags = preg_match_all('/<title>(.*)<\/title>/', $file, $matches, PREG_PATTERN_ORDER); return($matches[1][0]);} ?> Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 good link ten but were the heck were you yesterday and last week while i was making my own function work if i would have had this link i would have saved my self a week worths of work my back ground is not programming but EE i took fortrane in school so i know the basics and object oriented programming seems like a great deal but we need to be able to call a function from our server some how bash allows this you can write a script in bash and put it in the bin directory and call it from anywhere on your server anytime any way php needs this Quote Link to comment Share on other sites More sharing options...
scbookz Posted July 31, 2009 Author Share Posted July 31, 2009 where does include function go? <?php include('path/to/functions.php'); before the reference to the function or where? Quote Link to comment Share on other sites More sharing options...
TeNDoLLA Posted July 31, 2009 Share Posted July 31, 2009 Before you call that function in your code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.