PHP - Match Part Of A String Using An Array Of Needles
Hello,
I have several job categories on a recruitment website: $job_category[0]="accountant"; $job_category[1]="php programming"; $job_category[2]="baseball"; these job categories are contained within the urls imediately after the recruiting company's name and before the word "jobs", so we could have the following urls: www.url.com/company_name_accountant_jobs www.url.com/another_company_name_baseball_jobs www.url.com/yet_another_company_name_php programming_jobs Using the array $job_categories and the page path after the foward slash (e.g. yet_another_company_name_php programming_jobs) please could you tell me how to strip out the job category and the company name? (I'll extract the page path using a mod_rewrite) Thanks Stu Similar TutorialsDead simple, I know it is but I'm still a little newbie. I have this chat box, and I don't want people to be able to swear in it so I need help making a function where you call the string as an argument and it returns true if the string has any words from an array in it, Even if the word is walking and not just walk. If it's true I can replace the entire string with something else. Can someone tell me what functions I need? I prefer you didn't do it all for me I need to learn Thanks in advance! My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] Hi, how can I match two keywords in a string? eg. if keywords (Kids,Hoody) are in this string (Animal Kids Basic Hoody Blue) do something..... Thanks. Whats the quickest way to find a word in a string and wrap <b> tags around it? Code: [Select] $search = "php web"; $striing = "PHP is the web scripting language of choice"; Basically im looking for the output to be : "<b>PHP</b> is the <b>web</b> scripting language of choice" I am trying to make it echo if a string doesn't equal any of the values.
I have tried:
if(!preg_match("/none|Blue|Brown|Green|Grey)/i", $eyecolor)){ echo "Not an eye color"; } Hello, I am EXTREMELY new to PHP, and coding in general. I have attempted to search for an answer to this already, but I'm not sure I'm using terminology that will lead me to an solution, as I haven't come up with much. I'm hoping that someone can provide some assistance, or at least point me in the right direction for some reading. What I am trying to do it search a string for a match to any of 12 words. I'm wondering if there is a smarter way to do this than coding 12 different lines, each one looking for a specific word. If you can point me in the right direction, then thank you very much =) I'm using PHP to get a list of names from a mysql database, which then produces a drop down list for the user to select an option and then progress to the next page where the selection is displayed with other stuff. My problem is that my drop down list works fine, but when the user goes to the next page only the first part of the string is displayed, ie if the string is Fred Bloggs, only Fred is shown. I can get it to work by adding ' ' around the string name in the option section, but this shows 'Fred Bloggs' in the drop down list which isn't very pretty. I haven't got the actual code to hand at the moment, but any ideas on where I'm going wrong? Cheers Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. Hi i need help with some string manipulation and extraction.. http://www.test.com/forums/attachment/f39/745d1267084199-official-ar-m16-m4-picture-thread-dsc00005.jpg I need to extract an id from the above path dynamically. I need to extract the digits before the alphabet d after the second last path f39/ In the above case the number extracted would be 745. Can someone please help me out with it? hi php freaks, have link in a menu that looks like the following. I have been able search the string using strpos($lines[$i],'title='). What I want to know is how do I get the school summary into a variable. Code: [Select] <li><a href="../index.php" title="school summary">Summary</a></li> any help would be great Hello guys, I want to remove part of a string and convert it to a var instead of echoing it out.. How would I do it.. $string = "temp_photo/testing.jpg"; I want to remove temp_photo so the out put should be $filename2 = testing.jpg Please advise.. Thanks, Dan Hi - newbie to php - I need to search a string and possibly replace part of it. This is how I would do it in perl: Code: [Select] if ($homepage) { if ($homepage !~ /http/i) { $homepage = "http:\/\/" . $homepage; } } I have a homepage field in the database but sometimes people put the http in, and sometimes they leave it out. In perl I can figure it out and format accordingly but it doesn't work in PHP. I'm not sure if the first line even works in PHP. Maybe if to say something like: if $homepage is not equal to nothing. I'm not sure. Any help would be appreciated. Thanks. I have string like this (without the spaces) [ QUOTE="Adrock"]This is a test message[/QUOTE ] How do i get just what is between the double quotes taking into account in the message there could be double quotes? I've tried this but it doesn't echo anything unless i put the square brackets in but i want the username $origauth = html_entity_decode($message); $b = substr($origauth, strpos($origauth, '&#034') + 1); $c = substr($b, 0, strpos($b, '&#034')); echo $c; I have the following DOM document ( this is a sample document and is "as is", it's 100% intended to look like this ): <everything> <cars> <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it </cars> <houses> <house>Big Red House</house> </houses> </everything> This is all being put into a $newdoc = new DOMDocument(); $myString = ................. ; // ????? I only want the content of <cars> in here, and without having the <cars> tag How can I make this "$myString look like the following: $myString = ' <car>ladia</car> <car>ferrari</car> <garage>big blue building</garage> i also have a McLaren F1 but i wont brag about it '; Preferably without any looping. Hey guys I'm having an issue trying to get my PHP to display the first url of my exploded string and non of the others.
The SQL table column contains strings like this:
http://www.imgurl.com/image.jpg,http://www.imgurl.com/image2.jpg,http://www.imgurl.com/image3.jpg,http://www.imgurl.com/image4.jpg Hey there. Thinking this should be an easy one but I can only seem to find info on the string replace function. What I'm trying to do is strip everything after the @ from an email variable. So for example $mail variable comes in as me@gmail.com How would I strip the variable to only contain me and remove the @gmail.com I'll keep searching for the answer myself but if anyone can throw me a bone it's be appreciated. Cheers Hey guys! I found a flush function and it seems to be working well, but sometimes it will cut off characters. It's very strange. Here's my flush function: function out($str) { echo $str."<br />\n"; vbflush(); } function vbflush() { if (ob_get_length()){ @ob_flush(); @flush(); @ob_end_flush(); } @ob_start(); }And I'm calling it like this:out('Waiting 30 seconds until execution');And this is my output: Code: [Select] Waiting 30 seconds until executioAnyone know why? Hi all, first time here as I am a bit stuck. I am by no means a programmer and I was hoping that someone out there may have a simple solution to my problem?... So here goes" I have a voucher/offers site up-and-running. The site content is generated from an external feed. I want to create other sites and I want to track what sales/clicks have come from where. An example of the feed: (http://www.awin1.com/awclick.php?mid=251&id=28971&clickref=[URL_REFERENCE]&p=http://www.247electrical.co.uk) As you will see, I have [URL_REFERENCE] in each link. I want to automatically change that part of the string in the database. Does anyone have any thoughts? I have the following mapping array:
array( array('name'=>'nothing','options'=>array()), array('name'=>'aaa','options'=>array('a')), array('name'=>'bbb','options'=>array('b')), array('name'=>'ccc','options'=>array('c')), array('name'=>'aaa and bbb','options'=>array('a','b')), array('name'=>'aaa and ccc','options'=>array('a','c')), array('name'=>'bbb and ccc','options'=>array('b','c')), array('name'=>'aaa, bbb, and ccc','options'=>array('a','b','c')) ) Given array(), I would like to return 'nothing', given array('c'), I would like to return 'ccc', given array('b','c'), I would like to return 'bbb and ccc', given array('a','b','c'), I would like to return 'aaa, bbb, and ccc', etc. How is this best accomplished? As an alternate solution, instead of being given the above arrays, I could be given the following strings "", "c", "b~c", "a~b~c" and I can change the above mapping array to include these strings instead of the arrays I show. Please reference http://forums.phpfre...urn-sub-arrays/ for history. Would this be a better approach? How would I ensure the order of the JOINed values were always in the correct order for my mapping array? Code: [Select] array ( 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '1', ), 1 => array ( 'c0' => '6/114', 'c1' => '6/111', 'cnt' => '1', ), 2 => array ( 'c0' => '6/145', 'c1' => '6/116', 'cnt' => '1', ), ) I want to "match" as on example code 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '1', ), 1 => array ( 'c0' => '6/114', 'c1' => '6/111', 'cnt' => '1', ), c0 & c1, to get (and the array to be reseted) 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '2', ), 1 => array ( 'c0' => '6/145', 'c1' => '6/116', 'cnt' => '1', ), ) how to do it? I think that on only SQL it's impossible to do that ("switch"), furthermore I think that the code above would be useful /* $_c1 = @array_merge($_c1,$_c1x); if(!empty($_c0)) { foreach($_c1 as $value) { if(!isset($c1x[$value['id']])) { $c1x[$value['id']] = $value; $c1x[$value['id']]['cnt'] = 0; } $c1x[$value['id']]['cnt']++; } $this->tpl->assign('c1x',$c1x); } */ please help mi, thank you very much |