Jump to content

Search the Community

Showing results for tags 'string'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (Dreamweaver, Zend, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

  1. hay there How can i check for say 2 or more words in a string... Now I know this checks for 2 words on a "OR" basis if(preg_match("/$findthis|$this/i", $text_to_search)) { //do something } So this ill check to see if the $text_to_search contains either $findthis or $this but i need it to check with the "and" operator - so for example.. search $text_to_search for $findthis and $this how can i do this? many thanks
  2. I have an array containing the users input of 14 strings, I want to search this array to find duplicates, but I'm not sure how to go about it efficiently... there isn't already a function that does this by any chance is there? Thanks
  3. Fatal error: Cannot use string offset as an array in /..../ on line 6 { $bing_results[$b] = array ('url' => $value->Url, 'title' => $value->Title, 'snippet' => $value->Description, 'rank' => 100-$b); echo 'Lets see? : '.$bing_results[$b]['url']['title']['snippet']['rank']; $b++; }
  4. So I am working on a site which take's people's YouTube links and automatically embeds them into the website. The site's purpose isn't the playback of the videos rather the video thumbnail itself. I'm not saying that the site does not use the <iframe> tag to embed the video but it doesn't matter if the videos do play or not depending on things like Vevo or UMG rights etc... My problem is, I don't know how to take a full youtube url that a person enters and place it within a container that is an iframe, the url of course goes into the src=" " field. I found something that supposedly does this but I don't know how to apply it. I don't know how to take the link which comes in from a form and then before storing it into the database, apply a function to it to modify the string (add the container) The guy who wrote the code below said something easy yet I don't understand it... "all you have to do is parse the string then call the function" Can someone first answer, is this code actually doing what I want to do or do I misunderstand it? My understanding is, once a link is somehow accessed by the function autolink($string), it then first fixes the link to be sure it is proper, then if it is proper ($match), it is placed within the <iframe> container which happens to be an embed object. Please ignore my syntax so how do I take that string url link entered by the user on the form, then modify it, store it and retrieve to be displayed in an iframe? If you want to see what exactly I am doing, this is the site I am trying to make it on. You can see my other entries already which are just tests, I will empty the database once I get this thing running. It seems so simple but my ignorance hinders my progress. http://jchive.com/comments.html Thanks for any help. This is the link where the code came from : http://stackoverflow.com/questions/412467/how-to-embed-youtube-videos-in-php because it isn't the only code on the site, I will post the code: echo '<div id="chat_message">'.autolink($string).'</div>'; /****************Function to include****************/ <?php function autolink($string){ // force http: on www. $string = str_ireplace( "www.", "http://www.", $string ); // eliminate duplicates after force $string = str_ireplace( "http://http://www.", "http://www.", $string ); $string = str_ireplace( "https://http://www.", "https://www.", $string ); // The Regular Expression filter $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; // Check if there is a url in the text $m = preg_match_all($reg_exUrl, $string, $match); if ($m) { $links=$match[0]; for ($j=0;$j<$m;$j++) { if(substr($links[$j], 0, 18) == 'http://www.youtube'){ $string=str_replace($links[$j],'<a href="'.$links[$j].'" rel="nofollow" target="_blank">'.$links[$j].'</a>',$string).'<br /><iframe title="YouTube video player" class="youtube-player" type="text/html" width="320" height="185" src="http://www.youtube.com/embed/'.substr($links[$j], -11).'" frameborder="0" allowFullScreen></iframe><br />'; }else{ $string=str_replace($links[$j],'<a href="'.$links[$j].'" rel="nofollow" target="_blank">'.$links[$j].'</a>',$string); } } } return ($string); } ?>
  5. 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'?key=' $query is surrounded with ' ' when I try to echo. How do I avoid them?
  6. This code should be pretty self explanatory, but I'm struggling bad to get it to work. I want to check if the "propview" element is blank, if so, replace it with "No Contingencies". Simple right? $details_array = array( "propview" => JText::_('COM_IPROPERTY_PROPVIEW' ), "beds" => JText::_('COM_IPROPERTY_BEDS' ), "baths" => JText::_('COM_IPROPERTY_BATHS' ), "sqft" => (!$this->settings->measurement_units) ? JText::_('COM_IPROPERTY_SQFT' ) : JText::_('COM_IPROPERTY_SQM' ), "lotsize" => JText::_('COM_IPROPERTY_LOT_SIZE' ), "lot_acres" => JText::_('COM_IPROPERTY_LOT_ACRES' ), "yearbuilt" => JText::_('COM_IPROPERTY_YEAR_BUILT' ), "heat" => JText::_('COM_IPROPERTY_HEAT' ), "garage_type" => JText::_('COM_IPROPERTY_GARAGE_TYPE' ), "roof" => JText::_('COM_IPROPERTY_ROOF' )); if(empty($details_array["propview"])) { $details_array = array( "propview" => "No Contingencies" ); } It either doesn't do anything or it wipes out the entire array. Maybe the logic should be embedded in the original array, but I haven't found any examples that show that ever being done.
  7. Hi all, I hope some one can shed some light for me as how to send a carriage return and newline inside a spring that is being sent to a serialport. then read back to browser. The new lines are not working. I've tried \n \r \r\n <br> PHP_EOL. I can get this to work via the echo command but not when sending the spring via serial port. Thanks in anticipation. $serial->sendMessage("The big Brown Fox jumped over the cold lazey dog") . "<br>"; $serial->sendMessage("Message 2"); // Or to read from $read = $serial->readPort(); echo $read; echo "line 1" . "<br>"; echo "line 2" . "<br>"; echo "line 3" . "<br>"; I get the Result below. The big Brown Fox jumped over the cold lazey dogMessage 2line 1 line 2 line 3
  8. Hey guys, So i have a small yet very simple question more so than an issue. I am trying to call a variable that is a field from a mysql database. i am using an extract() function so any field title just returns as a variable. i have a member page where i then list the member and want to have on the side of their name the year they are born. for ex. <h1> Name ( year ) </h1> So in my data field the year the person is born is given as a full string of text 1984-14-09 Y/dd/m. All i want is the year from this data and to remove the day/month. So i did some research , and i came up with the solution of using an explode(), creating an array, and then simple echoing the index of that data i want. Problem is that the array is then leaving the entire string as one index in the array, basically not doing what i wanted it to do, which was to split the string into parts, allowing me to then echo whatever part i wanted. my code: <h1><a href="#link"><? echo $member_name; ?> (<? $arr = explode(' ',trim($member_birth_date)); print_r($arr); ?>)</a></h1> end result: any suggestions as to how to get the result i am looking for ? would really appreciate any ideas or solutions thanks guys
  9. Hi I appreciate your help, the code is kinda simple actually but I'm having trouble The following code echo's the WRONG result a5611bcd::0::0::abccef01 I need this following result a5611bcd::fffafaff::fefffeef::abccef01 I suspect the issue is that those two middle values are too large for integer, I know about bcmath, but whats the best way to get correct results into INTEGER form.. must be integer form, basically I my variables below are closely named sorry about this... <?php $KEY = array(0xA5611BCD,0xFFFAFAFF,0xFEFFFEEF,0xABCCEF01); /*this is the model of how everything below should end up in $SKEY $KEY = array(0xA5611BCD,0xFFFAFAFF,0xFEFFFEEF,0xABCCEF01); */ //so I begin with this string $getSKEY and try to make it into the above model $getSKEY = "A5611BCDFFFAFAFFFEFFFEEFABCCEF01"; $SKEY = array( hexdec(substr($getSKEY,0,), hexdec(substr($getSKEY,8,16)), hexdec(substr($getSKEY,16,24)), hexdec(substr($getSKEY,24,32)) ); echo dechex($SKEY[0])."::". dechex($SKEY[1])."::". dechex($SKEY[2])."::". dechex($SKEY[3]) ; ?>
  10. Hi Thanks for your help I'll just describe what I want to do any advice or if you could provide your own example it would really help, thanks again! I have a string holding hex numbers "41495ab3edde720c" and I want to get those values out of the string and represent them as hexadecimal thus 0x41495ab3edde720c, then I want to xor that hex with another hex like 0x41495ab3edde720c ^ 0x1111111111111111 then I want to take the result which will be in this example (50584BA2FCCF631D) and turn it back into a string "50584BA2FCCF631D" I'm not that good with php it seems hard to do this easily?
  11. Hi, PHP geniuses. I am a PHP novice and am stuck. For someone knowledgeable, this should be pretty easy, but it is stumping me. I have a site that is multiple languages. The only difference in the pages from one language to the next is a "/it/" at the end of the main url before the page name. I need 2 inline PHP statements that create hrefs: One that creates a link that says "remove 'it/' from the current page URL One that takes the current url and ads a 'it/" after the domain name and before the page name in a link. Example: If the current page URL is http://www.xxx.com/it/test/ - it creates a link that is http://www.xxx.com/test/ The second piece of code creates a link that changes http://www.xxx.com/test/ to http://www.xxx.com/it/test/ I have played with some PHP string replace commands, but I can't get it to work. I need something like: <a href='<?php echo str_replace ("/it/",""; ?>'> Anyway, bad code example, but you get the idea. Anyone know a quick fix here?
  12. Dear all, 10 years ago I was a skilled PHP programmer... Now after many years of inactivity I'm facing a newbye problem I can't figure out. I've written this piece of code: $found = array('uno','due', 'tre'); for ($i=0;$i<count($found);$i++){ echo $found[i]; } my output page is empty?? Shouldn't I see unoduetre? I mean I see in the debugger the array is fed and the loop is done!! Please be kind help me out, I feel like daydreaming... BR, Max.
  13. I want to look for the word "pant" within this string: "Pants: I'm going to be late!" How would I do this? I'd prefer it if I wasn't case sensitive search! This is how I'm trying to do it at the moment but it's not working! $status = "Pants: I'm going to be late!"; $changeValue = strtok($status, " "); $changeValue = strtolower($changeValue); $imageValue = "images/"; if($changeValue == "pant:"){ // if I change this value to "pants:" with the colon it works however I only want to search for the word "pant" without the "s" or the ":" $imageValue .= "pant.PNG"; }
  14. I have a php script that looks at a supplier website and queries from a pricing calculator, the script displays the result in a table. The result is my actual cost from my supplier and the price is displayed as a string. I need to convert my wholesale cost from a string to a value and then add my retail markup cost then display the Retail Cost as a string in my table. Unfortunately, I am a complete newbie and have been searching various methods, but no matter what I try, it fails. Here is the script: <?php // Request parameters $materialid = $_GET['materialid']; $sizeid = $_GET['sizeid']; $quantity = $_GET['quantity']; $numcolors = $_GET['numcolors']; // form URL for request //$url = "http://www.suppliersite.com/pricing?materialid=104&sizeid=37&quantity=1&numcolors=1"; $url = "http://www.suppliersite.com/pricing?materialid=".$materialid."&sizeid=".$sizeid."&quantity=".$quantity."&numcolors=".$numcolors; // Create DOM from URL or file $html = file_get_html($url); // Echo page //echo $html->plaintext; $price_per_item = $html->find('#price-per-item'); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $name = $html->find('h3'); //echo $price_per_item[0]."<br />"; //echo $total_price[0]."<br />"; //echo $description[0]."<br />"; //echo $name[1]."<br />"; // Iterate through all combinations: echo "<table id=\"products\">"; echo "<tr>"; //echo "<th>Price per item</th><th>Total Price</th><th>Product</th><th>Description</th><th>Size</th><th>Quantity</th>"; echo "<th width=\"25%\">Price per item</th><th width=\"15%\">Total Price</th><th width=\"30%\">Product</th><th width=\"10%\">Size</th><th width=\"10%\">Colors</th>"; echo "<tr>"; $price_per_item = $html->find('#price-per-item'); $total_price = $html->find('#total-price'); $description = $html->find('.description'); $size = $html->find('select[id='.'top-sizes-select'.'] option[value='.$sizeid.']'); echo"<tr>"; echo "<td>".$price_per_item[0]."</td>". "<td>".$total_price[0]."</td>". "<td>".$name[1]->innertext."</td>". // "<td>".$description[0]."</td>". "<td>".$size[0]->innertext."</td>". "<td>".$numcolors."</td>"; echo "</table>"; echo "<br />"; echo "<div style=\"width:40%\">"; echo $description[0]; echo "</div>"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB"> <head> <title>Extractor</title> <style media="screen" type="text/css"> #products { font-family:Arial, Helvetica, sans-serif; width:60%; border-collapse:collapse; font-size:12px; } #products td, #products th { font-size:1em; border:1px solid #777777; padding:3px 7px 2px 7px; } #products th { font-size:1.1em; text-align:left; padding-top:5px; padding-bottom:4px; background-color:#777777; color:#ffffff; } </style> </head> <body> </body> </html> Attached is a screenprint of the results, you will see the cost per item is $11.55 and I simply want to add 20% or as in the code: = price-per-item*1.2 -----so the price should show $13.86 per item I have tried to define a value such as: $RETAIL_price_per_item = $html->find(int('#price-per-item')*1.2); but that does not work I have tried many other versions and in different areas of the code but nothing works. Any help would be greatly appreciated. Thanks
  15. I'm trying to change the image within a html src="" attribute with PHP and can't seem to do it so the image will change on the fly. What am I doing wrong here? My code is below $image = "Trousers:"; if($image == "Trousers:"){ $imageChange = "images/socks.PNG"; } echo '<div id="itemImg"><img src="<?php echo $imageChange ?>" width="100px" height="100px" /></div>';
  16. This is an example of my code: $status = $entry->title; echo substr(strstr($status," "), 1) . substr($status, 0, -18); Below is the outcome: I'm feeling cold in this room. #emotionalclothingPants: I'm feeling cold in this room. I want the oucome to look like this: I'm feeling cold in this room. Thus removing the "#emotionalclothing" part of the string How can this be achieved? Thanks Stuart
  17. Hi, I am working on a PHP file and need it to open a URL and if there is a certain word or phrase on the web page then open a second URL. If the text is not there, then I need the first URL to continually open until the text is found. I would imagine this is pretty simple, something like an IF statement and a loop somewhere. But how do I do this? Any help would be greatly appreciated!
  18. I am coding a series of preg_replace expressions to try and strip unnecessary html/css code from text that was originally created using FCKEditor and is being copied programatically into CKEditor. All works well until I try to do a search/replace on a string that ends with a ">". No matter what I try this does not work, it either appears to do nothing or it errors and my resulting text is empty. In this case, if a table definition does not have a width defined, I want to add a width of 100%. The old/new strings and replace expression (str_replace in this case) are below. $oldstring = 'cellspacing="0">'; $newstring = 'cellspacing="0" width="100%">'; $textstring = str_replace($oldstring, $newstring, $textstring); It seems that the problem is related to the ">". If I take this out, it works ok. However I want to be sure that "cellspacing" is the last tag for a table definition (the tags were added automatically by FCKEditor and are always in the same order). Thanks for any help. I have been tearing my hair out for hours over this.
  19. Hi Guys, I am currently writing some pretty messy code and I am having problems with it. I bascially have a script which will change the source of an image using jquery, but all of this is generated through a PHP file. So basically I have this being called using ajax: $sql="select * from vehicle_image where vehicle_id=".$_REQUEST["id"].""; $sql_res=mysqli_query($conn, $sql) or die(mysqli_error($conn)); while($array=mysqli_fetch_array($sql_res)) { $src=$array['image_src']; $variable = "\"../timthumb.php?src=images/" . $src. "&w=66.6&h=66.6\""; $content .= "<img onclick=\"changeImage(" . $variable. ")\" style=\"float:left;\" src=" . $variable . ">"; } echo $content; The line I am having the problems with is the $content .= line. specifically the onclick=" this bit here " part. However I write the code, however I escape the characters, it causes an error with different bits of the code, at the moment the problem with this is that is doesnt form the variable in the function properly. I am using FireBug to check that things are workly properly as when you use jQuery the source code does not update. Firebug says there is something wrong after changeImage( so I can only assume its my character escaping, but I really dont know. Any help on this would be great!
  20. Hi. I've got a weird problem with mysql. I import data's from XML to mysql. Everything goes fine until the part where I need to insert a string value to "name" field. I swear I've got this all good. I've even echoed the value before insert it to database. But the values just not goes in to the database. I just have a simple insert query mysql_query("INSERT INTO items (name, description, etc) VALUE ('$name','$desc','etc')"); So for the first 12 rows it inserted the $name into name field, however from row 13th to somewhere in row 1000th, the field 'name' are just empty (only field 'name', so description, etc are filled in), then continue insert the data until the rest. I have tried to echo the empty data's, they are not empty. What could possibly happen to this?? How can I debug this? Help would be appreciated. Thank you. Ayok
  21. In my site, I have a functions.php file and I store all functions for the site ( A news site, with memberships, profiles ) So, I am still making the site, and 80% is finished, but the I feel like the file is going to slow my site down, I just checked it and I have reached 500th line on notepad++. So, I just want to know how much is too much really. What is the effect, or the best practices when putting all your functions in one file. Suppose, this for instance. There are functions that are used 10 or 20 times more than other functions. In my case, every time user browses the index page, there will be atleast 1 function that will be started. ex: ( out putting an article. ) And, there are others functions that rarely get called, like user registration, login.... So, is it ok to separate functions in different files according to their time of use? or not? I generally want to know, ( Since I am newbie ) how you deal with functions, and the best methods. Thanks.
  22. Hi, I have a string which I am pulling from a MySQL DB which unfortunately looks like the following. <p><img src="myimage.jpg" border="0" /></p> <p>My short paragraph</p> I would like to pull out <img src="myimage.jpg" border="0" /> and place it in a separate variable 'strImage' (so I can echo it elsewhere), and then place the remainder of the string in a second variable 'strText'. Note: The <img src> and <border> values will vary depending on the article I pull from the database. What method should I use to make this happen? Thank you so much for your help in advance! Matt
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.