InfiniteWarrior Posted December 3, 2012 Share Posted December 3, 2012 At the moment I have a database with a variable located at the bottom of every entry.... there are 10,000 entries which need to have the variable moved or copied to another field column corresponding with each entry...... The variable is always located in a specific segment of text which looks something like this.... <b>String: # xxxx.xx</b> - so if the script could locate the phrase <b>string: # and then retrieve the subsequent number, and move or copy that number into a corresponding field on the same table of the MySQL database, this would be extremely useful....,, and save me days of data-entry.... I barely know any PHP, yet I did take computer science and study Java and Perl 6 years ago...... so I understand basic coding principals.... Could anyone point me in the right diection of basic PHP scripts or functions which can help me work in MySQL databases..? Love & Light Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/ Share on other sites More sharing options...
BrettHartel Posted December 3, 2012 Share Posted December 3, 2012 Unfortunatly, I am still learning PHP, but www.w3schools.com offers a great list of commands that you can uses with php and mysql databases. Maybe reading the PHP section will help you in your journey. Love & Light, Brett Hartel Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397339 Share on other sites More sharing options...
MDCode Posted December 4, 2012 Share Posted December 4, 2012 Unfortunatly, I am still learning PHP, but www.w3schools.com offers a great list of commands that you can uses with php and mysql databases. Maybe reading the PHP section will help you in your journey. Love & Light, Brett Hartel Unfortunately w3schools uses out of date material with security not in mind. I would not suggest using them as a beginning into php Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397377 Share on other sites More sharing options...
InfiniteWarrior Posted December 4, 2012 Author Share Posted December 4, 2012 Been looking, found basic MySQL functions and whatnot..... this isn't the issue.... I basically just need a way to search and replace the text...... can anyone show me a script to locate a string of text, and return a decimal value number which follows the string of text.... , which is a numeric decimal number between 4 and 7 characters in length? Then I need to find a way to repeat this for every field in a table or to parse one large text/excel file and return a list of values for every instance of the specific string in question..... I would pay someone if I could I am just broke..... Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397394 Share on other sites More sharing options...
InfiniteWarrior Posted December 4, 2012 Author Share Posted December 4, 2012 The issue is how to define the variable as a strictly numeric decimal number in that length range which follows the occurrence of a separately defined variable which is the string of text which always precedes the decimal number..... parsing a file and outputting data is relatively easy.. I'll figure it out eventually..... something like variable $string = "<b>string: # " then the variable following the string needs to be defined as a decimal number with a length of 4-7 characters then that variable needs to be returned, and placed into a text file on a single line.... I am unfamiliar with any php syntax.... I am figuring it out. Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397395 Share on other sites More sharing options...
InfiniteWarrior Posted December 4, 2012 Author Share Posted December 4, 2012 Ended up finding a way basic function in OpenOffice Calc to return a variable from a string...., using the mid, left, and right functions built in...., then modifying further with there to whittle away the unneeded characters with advanced search and replace functions, as the string length was variable in number of characters... only explaining because I know people will be searching similar inquiries in the future on google so always positive to post solutions, didn't have time to learn PHP in one night. Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397400 Share on other sites More sharing options...
Christian F. Posted December 4, 2012 Share Posted December 4, 2012 (edited) You could solve this is two ways with PHP, which you should use depends a bit on the details of the pattern you want matched. The quickest method, but also the most technically complex, is by using Regular Exp<b></b>ressions. They'll allow you to create a pattern rule, to match (and retrieve) whatever you like in regular text. Your example is border-line, as it contains HTML. To get the IDs from your example, something like this should suffice: $RegExp = '/String: #(\\d+(:?\\.\\d{1,2})?)/'; if (!preg_match_all ($RegExp, $Data, $Matches)) { die ("Could not find any IDs in data."); } That RegExp will search for the text "String: #", followed by one or more digits (\d, + means "one or more"), potentially followed by a period (\.) and one or two digits (\d{1,2}). Then it'll save the results the array $Matches, so that you can loop through it and do whatever you wanted with the values. The other, possibly more proper, method in this case would be to use the DOMdocument class. Click on the link to learn more about it. Edited December 4, 2012 by Christian F. Quote Link to comment https://forums.phpfreaks.com/topic/271563-modify-mysql-finddelcopymove-variables/#findComment-1397443 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.