PHP - Extracting Data From String
so I'm working on this system which requires me to inject anime show names into a DB for an index.
I get them in this form: [Kira-Fansub]_HIGHSCHOOL_OF_THE_DEAD_-_04_(BD_1920x1080_x264_AAC) [F0E73009].mkv I need to get it in this form: Highschool Of The Dead sometimes the words are space seperated. the main part is to extract the text in between the ] and ( and with that i mean [stuff]extract this(other stuff) and sometimes it looks like this: [stuff]extract[stuff] I have NO CLUE how to do this preg_match_all doesn't get me any further.. maybe in stages? Similar TutorialsI have a string Code: [Select] <p>Bollywood romcom: a pair of wouldbe suicides choose the same bridge at the same time.</p><p><a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a> (<a href="http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66" target="_blank">www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66</a>), Ozone Leisure Park, Grenoble Road (next Kassam Stadium), Oxford OX4 4XP; Tel. 08712 240 240 (10p per min from BT).<br /> </p> Using php i want to extract Code: [Select] http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66 from the <a> tag. I have already tried using <?php $pattern = "/<a href=\"([^\"]*)\">(.*)<\/a>/iU"; preg_match_all($pattern, $link, $matches); var_dump($matches); ?> The output I get is array 0 => array 0 => string '<a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a>' (length=81) 1 => array 0 => string 'http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema' (length=56) 2 => array 0 => string 'Vue Cinema' (length=10) This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 hey guys i need to extract all the IP's of a string and loop them for more operations but for some reason i only get the first one <?php $string = '80.37.14.13 80.37.14.14 80.37.14.15'; preg_match("/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/", $string, $matches); foreach ($matches as $ip){ echo "$ip<br>"; } ?> The string is not really seperated by spaces ... it can actualy be messy and have ips rapped arround a lot of code. The regex works because i do get the first one ... What did i miss? I have managed to get this to work but it seems like it is a very long and messy solution. I was wondering if anyone had an idea of how this can be done better. I am new to php and don't know a lot. It shows the text between the tags <h1> and </h1> from the content of a different file Basically I had to start the substr() from the fourth position so it would actually skip the "<h1>" being included, and because I started on the fourth postion I then had to finish four places back to skip the "</h1>" being included. Code: [Select] <?php $id = $_GET['id']; $homepage = file_get_contents("./".$id.".php"); $title = stristr($homepage,"<h1>"); $titlepos = strpos($homepage,"</h1>"); $endpos = $titlepos - 4; echo "Title " . substr($title,4,$endpos); ?> I have a string that looks like /index.php?g1=111&g2=222&g3=333. How can I obtain the value of g1 (i.e. 111)? It does not represent the current state of the server thus I cannot just use $_GET. It also is not necessarily the first item. The script below appears to work, however, http://php.net/manua...n.parse-url.php states This function is intended specifically for the purpose of parsing URLs and not URIs. However, to comply with PHP's backwards compatibility requirements it makes an exception for the file:// scheme where triple slashes (file:///...) are allowed. For any other scheme this is invalid. It appears that my string is a URI and not a URL, but I might be wrong. How should this be accomplished <?php $str='/index.php?g1=111&g2=222&g3=333'; $array=parse_url($str); parse_str($array['query'],$get); echo("<p>{$get['g1']}</p>"); ?> hi there - hello dear PHP-Friends, good evening! - i want to extract some data ouf of a large html-file. i have - a very very large amount of data: approx 5000 x the following line-sheme!: Quote 67003 Cato Bontjes Vice Versum House 1 28832 Achim 62042 Cato Bontjes Vice Versum House 2 28832 Achim 41798 Cato Bontjes Vice Versum House 3 37139 Adelebsen 40034 Cato Bontjes Vice Versum House 4 21365 Adendorf 46218 Cato Bontjes Vice Versum House 5 31855 Aerzen 42481Cato Bontjes Vice Versum House 6 21702 Ahlerstedt 49761 Cato Bontjes Vice Versum House 7 26197 Ahlhorn Question: how can i extract the first 5 first digits...!? I have allready some solutions here - i need a very very robuste solution diblertone1 What I'm trying to do is take two arrays and combine them using array_combine. After they are combined I want to take each key and value pair and use them in a string to build a MySQL query. See below for some pseudo-code =D <?php $fields = array('first_name', 'last_name'); //the fields that will be set with an UPDATE query. $newvals = array('Joe', 'Blow');//The values that will go into $fields $arr = array_combine($fields, $newvals);//Each value now has a key of the field it will update. /** This is where I want to return my SET string with something like 'SET ' . $arr['first_name'] ' = ' . $arr['first_name_value'] ', etc etc. */ There it is, I suppose. Are there any easier ways of doing what I'm trying to accomplish, that is, am I on the right track or just making things harder for myself? Both arrays will have dynamic values throughout my application, so I need to be able to get both each field and value for each query. Any links to some constructs, etc, etc? That's all I really need and I can post the solution when I've figured it out. I'm *attempting* to write a script that will take a paste of data from a user and when it's submitted it will drop certain parts of the data into databases and be available for recall later. I have the MySQL sorta out I think but I can't test until I get this part done. Basically people will paste a copied paste (CTRL A, CTRL C and go to my form and just hit CTRL V). It will contain a bunch of data I want to drop in the database but in different areas, like the following example the items in bold are the items I want to grab. First Name: Lincoln Last Name: Coe Address: 1234 Easy St, Perfectville, PV 00000 Telephone: 0000000000 $example "Q: Example? A:" Let's assume that I'd like to display $example but exclude "Q:" and "A:", how would I do that? I usually only do design work, but a client wanted a log in system to his website, so I decided to do it. I set everything up correctly, and users can sign up, login, and log out. However, he wants to be informed when a user logs into his site. So say (user x) wants logs in, my client wants to receive an email with all of (user x)'s account information. How do I pull a row from mysql based on the login information provided? My database is has 7 columns: user, pass, name, address, state, phone, email Hi there I need to extract data from some XML. I have found a few sites that explain that part to me, however there is a section of the data which I need to extract and am not sure how to go about it. Below is an extract of the XML, the section I am trying to extract is highlighted in red (it is essentially a text message being sent I am trying to get the contents of the sms/text message): <usa_smpp_host>THTTP</usa_smpp_host> <short_message>id:660352946 sub:001 dlvrd:001 submit date:1102081032 done date:1102081035 stat:DELIVRD err:000 text:Test SMS message</short_message> <dest_addr_npi>1</dest_addr_npi> Any assistance would be appreciated. Have played around quite a bit but have not managed to figure it out yet. thanks I have an RSS feed, with alot of data of lottery numbers. the feed itself is : http://www.alllotto.com/rss/NY/latest.rss The item i am interested in is: Quote <item> <title>Take 5</title> <description>2011-08-27: 4, 10, 16, 17, 31</description> <guid isPermaLink="false">USA-New-York-Take-5-2011-08-27</guid> </item> How could I output those to varibles? thanks Joe I've only been studying PHP for a week now and have come across this problem which I'm sure there is a simple answer to, but I just can't figure it out and would appreciate some help. I've spent far too long on this minor issue already! I have a table which contains a list of products, in this case books, which stores the date when each new item is added. I have a query that then searches through this table and extracts the 6 most recent additions. Here is the code I have so far: Code: [Select] $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 6"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $title = $row["title"]; $author = $row["author"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamiclist .= //My table showing the products } } else { $dynamicList = "There are currently no Books listed in this store"; } This works well when I need to display the 5 most recent products in a normal table fashion, one below another, on the page. However, I want to display the products in a more personalised order. For example display the newest item in one section of the page and 3rd newest in another. What is the best way to select an individual row from a query? To extract the details of the 2nd newest item to display in the header, for example. Thanks for your help. Hi guys, This is my problem: I have a csv file let's say have these values: blue,1,2,3,4 red,8,5,6,7 I need to add thes values into a 2d array to be able to use like this: colors[1][2]=2 colors[2][4]=7 Where my first number is the row and the second number is the value within that row. This is what I got so far <?PHP $i=0; $j=0; $file_handle = fopen("color-list.csv", "r"); while (!feof($file_handle) ) { $colors = fgetcsv($file_handle, 10000); for ($j=0; $j<=4; $j++) { $row[$i][$j]=$colors[$j]; print row[$i][$j]; } $i++; ?> For some reason this doesn't work. Maybe I am declaring the arrays wrong. Thank you! I have 2 sites. 1 site is a store the other is a blog. The homepage of the store shows random product images. Each image links to it's product page. I'm using the code below to get data from the store homepage into a variable: Code: [Select] <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.somesite.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); ?> I can echo $output and see the page displayed on my page. So that part is working. On the blog, I want to display random products and link them back to the store. How can I extract just the images & their page links from the $output variable? Hello all, I have a problem I'm not sure how to tackle. I have data in a database that looks looks like this: Field1 | Field2 AA | AA Row 1 Data AA | AA Row 2 Data AA | AA Row 3 Data AB | AB Row 4 Data AB | AB Row 5 Data AB | AB Row 6 Data AC | AB Row 7 Data AC | AB Row 8 Data AC | AB Row 9 Data AC | AB Row 10 Data I would like to grab and output JUST the first AA, AB, AC and the the row data in field two? So the loop would catch the first AA then when field1 data has changed it will output the first AB and so on... So the output would look like: Row1: AA : AA Row 1 Data Row2: AB : AA Row 4 Data Row3: AC : AA Row 7 Data Is there a way to accomplish this? Any help would be great! Thanks! Hi - I have an array where one of the values delivers a string. Here is the output from a print_r($pickupdates): Code: [Select] Array ( [0] => Array ( [location] => Clearwater [TheDates] => 1311746700,1321746641,1331668779 ) [1] => Array ( [location] => Canmore [TheDates] => 1311746700,1321746641,1331746641 ) [2] => Array ( [location] => Collingwood [TheDates] => 1311746700,1321746641,1331746641 ) [3] => Array ( [location] => Varsity [TheDates] => 1321746641,1330746700,1331746700 ) The challenge is to get the location and TheDates into a nice HTML table which would look like this: Code: [Select] LOCATION DATE 1 DATE 2 DATE 3 Clearwater April 1 May 1 June 1 Varsity April 2 May 2 June 2 Collingwood April 3 May 3 June 3 Canmore April 4 May 4 June 4 Ok - Now I am stuck, I need to be able to uniquely identify each date that is associated with the location such that I can run a foreach() on then so I can populate the table properly. I tried using list() and explode. List does not separate the dates and explode needs a string not an array. I'm really stuck - a very big Heartfelt thanks to anyone who can steer me in the right direction. MANY THANKS ! I need help on extracting of data from another website, commonly known as screen scrapping. I was able to do it with a basic created function, but it doesn't work for extracting data out from a table of another website. I want to extract the data from each row and data of this site http://online.wsj.com/mdc/public/page/2_3021-usetf.html, so that I can put these data into my database. My current code is <?php $data = file_get_contents('http://online.wsj.com/mdc/public/page/2_3021-usetf.html'); $regex = '/You(.+?) registered/'; preg_match($regex,$data,$match); var_dump($match); echo $match[1]; ?> Anyone has a script that I could modify to do that? Thanks! Hey all, I wrote a crawler and have already written the string to extract links. i get a multidimensional array. this is #13 for example Array[0][13] => <a class="menuitem" href="/home-news.html" title="Home / News">Home / News</a> Array[1][13] => /home-news.html ok so far so good. Now I want to extract the name Home / News and write that into a database and the link as well. can i use the preg_match_all() to search an array? or how can i extract it? Thanks so much! monkover Hi, I have an XML Feed which is using ID's or Types. I need to select the specific node and convert it to a variable. Example XML Feed: Code: [Select] <tour> <tourName>Amazon Riverboat Adventure</tourName> <dossierCode>PVIIA</dossierCode> <tripDetails> <tripDetail type="StartFinish">ex Lima</tripDetail> <tripDetail type="What's Included">Lots of stuff </tripDetail> </tripDetails> I have been extracting this data by using: <?php if(!$xml=simplexml_load_file('xmlfeed.xml')){ trigger_error('Error reading XML file',E_USER_ERROR); } foreach ($xml->tourName as $tourname) foreach ($xml->dossierCode as $agentcode) ?> However I am unsure how I can extract the "ex lima" from StartFinish as $startfinish. Can anyone help? Many thanks! |