PHP - Strtoupper Inside Preg_replace Not Working
For all of you RegEx experts...here is my code:
$str=preg_replace("/\[word=(.)(.*)\](.*)\[\/word\]/Usi", "<a href=\"http://www.accountingconcern.com/accounting-dictionary/".strtoupper('\\1')."/\\1\\2/ \">\\3</a>", $str); Basically it is taking [word=debit]Debit[/word] and making it link. The problem is, where I have the first \\1, I need that letter capitalized - not working. I'm not getting an error, it is just not capitalizing that letter. Any ideas? Thank you! Similar TutorialsI am trying to add some quick tagging features to my site where you put in a code like "[IMG:1]" and my function will translate that into an image with an id of 1. I though I could put the whole page in a variable and replace anywhere that matched the pattern. When I try to use a switch() inside the function that replaces the preg_replace matches, the variables I expect to be there, aren't there. It isn't working because the variable "IMG" and "1" show up as "$1" and "$2" to the code. Is there another way to do this? function gCodes($code,$var) { switch($code) { case "IMG": $img = getImage($var); $return = "<a href=\"$img[location]\"><img src=\"$img[location]\" alt=\"$img[title]\"/></a>"; break; default: $return = "$code=>$var<br>Not Working<br>"; break; } return $return; } $text = "[IMG:1]"; $content = preg_replace("/\[([A-Z]{3}):([a-zA-Z0-9]+)\]/",gCodes("$1","$2"),$text); echo $content; The above example prints out: Code: [Select] IMG=>1 Not Working Hi all. I'm having a bit of an issue with preg_replace and I'm not sure how to solve it. I'm having preg_replace find a "bus" (short for business) prefix in a file name and then print "Business Management" instead of "bus". I also have another prefix of "bus_it_requests". When preg_replace finds that prefix, it prints "Business Management It Requests" but I need it to print "Business It Requests". How do I have preg_replace make the distinction in the prefix matches? Code: [Select] $str = preg_replace('/('.$word.')/i', '<em>\1</em>', $str); how come this doesn't work when $word = 'http://www.google.com', or any other URL? How come preg_replace won't traverse multiple lines?
<?php
$str = ' i want to remove any links which get pulled out in my general information query. Code: [Select] $general_info = $row['general_info']; $general= preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '', $general_info); echo '<h2>General Information : <img src="images/mag.png"></h2>'; echo '<div id="featurecontent">'; echo '<p>'. ucfirst($general).'</p>'; echo '</div>'; But the above code doesnt seem to be stripping out links. Can anyone see what i am doing wrong. Kind Regards Dean Hello,
A not so experienced PHP-user here. For my school assignment, I have to make the following:
"Stolwijkstraat 8" has to be shortened into SW with use of SUBSTR and STRTOUPPER.
My question:
1. How can I be able to use SUBSTR and STRTOUPPER in the same line?
2. How can I be able to remove everything in the line ''Stolwijkstraat 8", on behalf of ''S'' and ''w''?
A quick response would be greatly appreciated.
Kind regards.
Hi - wondering if someone can give a little guidance: Why doesn't this trim the whitespace out of the string postzip? trim(strtoupper(((isset($_POST["postzip"]))?$_POST["postzip"]:""))) Thanks I'm trying to create a Facebook fangate, and I want an imagemap to come up to fans, but a static image to come up for non-fans. Here's the code. Someone please tell me what I'm doing wrong. I've tried it 3 different ways. (I searched Google and this forum before posting...nothing I found worked for me). While I've removed identifying information, I have tested and made sure the bitmapped image works properly (can call it through facebook on its own) as well as the regular image. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <link rel="stylesheet" type="text/css" href="style.css" /> <style type="text/css"> body { width:520px; margin:0; padding:0; border:0; }</style> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <? require 'facebook.php'; $app_id = "XXXXXXXXX"; $app_secret = "XXXXXXXXXXX"; $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true )); $signed_request = $facebook->getSignedRequest(); if ($like_status) { ?> <div><img src="http://xxxxxx.com/facebook/FBnavbar.png" alt="" usemap="#FB Nav Bar" style="border-style: none" /></div> <div> <map id="FB Nav Bar" name="FB Nav Bar"> <area shape="rect" alt="About xxxxxx Social Media" coords="6,21,80,42" href="http://www.facebook.com/xxxxxxx?sk=info" title="About xxxxxx Social Media" /> <area shape="rect" alt="xxxxxx Blog" coords="222,24,276,38" href="http://www.facebook.com/xxxxxxxsk=app_?????" title="xxxxxx Blog" /> <area shape="rect" alt="xxxxxx Social Media" coords="297,23,391,39" href="" title="xxxxxx Social Media" /> <area shape="rect" alt="Contact xxxxxx Social Media" coords="409,23,508,39" href="../../../contact/" title="Contactxxxxxx Social Media" /> <area shape="rect" alt="Subscribe to our RSS feed" coords="443,1,459,14" href="http://feedburner.com/xxxxx" title="Subscribe to our RSS feed" /> <area shape="rect" alt="Share us on delicious" coords="463,0,478,18" href="http://www.delicious.com/share?new=1&hash=e16eda577a70c83c0dfa2c8c29e52d24&key=tnNrKLSea55V6Tkd2ze9ujDWVOs-&title=xxxxxxx%2xxxxp%20Reputation%20Management&url=http%3A%2F%2Fxxxxxxx%2F&jump=%2Furl%2Fe16eda577a70c83c0dfa2c8c29e52d24" title="Share us on delicious" /> <area shape="rect" alt="Add us on LinkedIn" coords="485,3,499,18" href="http://www.linkedin.com/company/xxxxxx" title="Add us on LinkedIn" /> <area shape="rect" alt="Follow our Director on Twitter" coords="503,1,519,17" href="http://www.twitter.com/xxxxxxx" title="Follow our Director on Twitter" /> <area shape="rect" alt="Learn about xxxxxxxx's Services" coords="98,21,202,40" href="http://www.facebook.com/xxxxxx?sk=app_?????" title="Learn about xxxxxxx's Services" /> <area shape="default" nohref="nohref" alt="" /></map></div> <?php } else { ?> <img src="http://xxxxx.com/facebook/landing/SRfanpage3.png" /> <?php } ?> </body> </html> I'm very new at this (not a php coder, just grabbed some code from a tutorial and am trying to make it work), so please be gentle. Thanks for your help in advance. Hello,
I have a song streaming website, and i want to set a cookie inside a player popup to avoid that users increment the number of times that an album was played every time they access it.
I want the cookie to last at least 6h, but every time i test the code with 1,2 or 5 minutes it never ends in the time that i specify. For example i want it to last 3min and it may take 5 or 2min to end. Cant figure out why, because i used the same cookie code in a none popup window and it worked.
// player.php (POPUP) <?php session_start(); include("include/player-functions.php"); uniqueAlbumListens($db,$_GET['id']); (...) ?> //player_functions.php <?php (...) function uniqueAlbumListens($db,$id){ if(!isset($_COOKIE["ml".$id])){ updateListens($db,$id); } setcookie("ml".$id, "listens", time()+60*2); // 2minutes -> 60*2 ? || 6h -> 60*60*6 ? } (...) ?> Hello everyone.
please I have problem with printing out a value from inside an array of a nested json. ive tried several ways its always returns "index not define". $valr= "https://ice3.com/api/v1/orderbook/ticker"; ////////////////////////////source $valrGet = file_get_contents($valr); $valrD = json_decode($valrGet, true); $valrSell = ["ask"] ["price"]; Here is the structure of the json from the source : {"errors":false,"response":{"entities":[{"pair_id":3,"pair_name":"BTC\/ZAR","ask":{"price":"179382.54","amount":"0.05357142"},"bid":{"price":"177229.4286563","amount":"0.0011"}},{"pair_id":4,"pair_name":"BTC\/NGN","ask":{"price":"8890000.00","amount":"0.10"},"bid": my target is to output the value of ("price") from "pair_name" BTC\/ZAR please help. Thanks in advance The Script:
$desired_width = 110; if (isset($_POST['submit'])) { $j = 0; //Variable for indexing uploaded image for ($i = 0; $i < count($_FILES['file']['name']); $i++) {//loop to get individual element from the array $target_path = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/uploads/"; //Declaring Path for uploaded images $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed $ext = explode('.', basename($_FILES['file']['name'][$i]));//explode file name from dot(.) $file_extension = end($ext); //store extensions in the variable $new_image_name = md5(uniqid()) . "." . $ext[count($ext) - 1]; $target_path = $target_path . $new_image_name;//set the target path with a new name of image $j = $j + 1;//increment the number of uploaded images according to the files in array if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded. && in_array($file_extension, $validextensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) {//if file moved to uploads folder echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>'; $tqs = "INSERT INTO images (`original_image_name`, `image_file`, `date_created`) VALUES ('" . $_FILES['file']['name'][$i] . "', '" . $new_image_name . "', now())"; $tqr = mysqli_query($dbc, $tqs); // Select the ID numbers of the last inserted images and store them inside an array. // Use the implode() function on the array to have a string of the ID numbers separated by commas. // Store the ID numbers in the "image_file_id" column of the "thread" table. $tqs = "SELECT `id` FROM `images` WHERE `image_file` IN ('$new_image_name')"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $fetch_array = array(); $row = mysqli_fetch_array($tqr); $fetch_array[] = $row['id']; /* * This prints e.g.: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 ) */ print_r($fetch_array); // Goes over to create the thumbnail images. $src = $target_path; $dest = $_SERVER['DOCUMENT_ROOT'] . "/gallerysite/multiple_image_upload/thumbs/" . $new_image_name; make_thumb($src, $dest, $desired_width); } else {//if file was not moved. echo $j. ').<span id="error">please try again!.</span><br/><br/>'; } } else {//if file size and file type was incorrect. echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>'; } } }Hey, sorry that I am posting this darn image upload script again, I have this almost finished and I am not looking to ask more questions when it comes to this script specifically. With the script above I have that part where the script should store the ID numbers (the auto_increment column of the table) of the image files inside of one array and then the "implode()" function would get used on the array and then the ID numbers would get inserted into the "image_file_id" column of the "thread" table. As you can see at the above part the script prints the following: Array ( [0] => 542 ) Array ( [0] => 543 ) Array ( [0] => 544 )And I am looking to insert into the column of the table the following: 542, 543, 544I thought of re-writing the whole image upload script since this happens inside the for loop, though I thought maybe I could be having this done with the script as it is right now. Any suggestions on how to do this? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=316454.0 I'm trying to search a string for all occurences of a pattern, then append text after that pattern. The example is:
SUM("foo") as "bar"
and have it display as:
SUM("foo") over() as "bar"
The "SUM" could be any SQL aggregate and be case insensitive. So For bonus points, let's say the valid aggregates are array('SUM', 'MAX', 'MIN', 'AVG'). My plan right now is to figure it out for SUM, then loop it replacing the aggregate.
This is what I have so far... and it is not working.
$l= 'SUM("foo") as "bar"';
$l=preg_replace('/([^"]+")/','\0 over()',$l);
Thanks,
Ryan
Hello ppl, I have this website link http://www.somesite.com/anotherpage/yetotherpage.html what i want to make is using preg_replace that the final result will be www.somesite.com After days of searching I found this thread http://www.phpfreaks.com/forums/index.php?topic=236954.0 that helped me do what I was trying to do. I've gotten the code to create and rename my html document but I can't figure out how to use the preg_replace part. This is my template with the 3 variables I want to replace with values from a form. Code: [Select] <html> <head> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php include_once('content.php') ?> </body> <SCRIPT language="JavaScript" SRC="javascript.js"></SCRIPT> <script type="text/javascript"> function nametitle(){ parent.iframe1.document.getElementById("div1").innerHTML = "VARIABLE1 <br>VARIABLE2"; parent.iframe1.document.getElementById("quotes").innerHTML = "VARIABLE3"; } </script> </html> I've spent hours reading and trying to understand how to make it work but it's a little over my head. Could someone help me with this? Thanks, i have: $msg = ereg_replace("[^A-z0-9]"," ",$msg); $msg = ereg_replace(" "," ",$msg); $msg = ereg_replace(" "," ",$msg); how will i apply preg_replace please??? thank you I am trying to pull out the image HTML tag but its not working as expected. Here is what I am doing $removeimagetag='/<a href/'; $replacwith = "illegal"; $_POST['descr']=preg_replace($removeimagetag,$replacwith,$_POST['descr']); in the 'descr' there is a <a href="http://s635.photobucket.com...... When it post it does not strip out the <a href So the image is displayed. I tried a modified version to test to see if it work that looked like this. $removeimagetag='/goofy/'; $replacwith = "illegal"; $_POST['descr']=preg_replace($removeimagetag,$replacwith,$_POST['descr']); When the word goofy appears in the text then its replaced with the word illegal, Also I would like to make it so that it replaces the entire line from the <a href....... to the </a> with a phrase that says "this feature is not allowed" rather than just the part in the front...the <a href. Any help you can be will be greatly appreciated. Hi, I'm kind of new to PHP and very new to Regular Expressions and I was wondering if someone could help run through this code snippet from a callback function in a Joomla plugin called Affliates Feed. So far I have this is passed a pointer to variable item (I understand this is effectively the same as passing the variable but a lot less CPU intensive. Creates an array with keys and values Now the for loop I am stuck with, I understand the interation through the array. But what is preg_replace returning and why pass it back that way hasn't it already done its job? Can any one help? And please feel free to be as basic as possible :help: Thanks, Adam Code: [Select] function gardening(&$item) { #renaming categories, not the most efficient use for example strtolower first, and use only lowercase in the rename array $rename=array( ' Gardening?' => '', 'Climber Plants' => 'Climbing Plants', 'Seeds.*Bulbs' => 'Seeds Bulbs', 'Plant protection' => 'Horticultural goods', 'Garden structures' => 'Garden buildings',); foreach ( $rename as $k => $v ) { list($item['menu_1'],$item['menu_2'])=preg_replace("#$k#",$v,array($item['menu_1'],$item['menu_2'])); } $item['menu_1']=ucfirst(strtolower($item['menu_1'])); $item['menu_2']=ucfirst(strtolower($item['menu_2'])); $item['menu_3']=ucfirst(strtolower($item['menu_3'])); $item['menu_4']=ucfirst(strtolower($item['menu_4'])); } Hi there! I need to echo some text from a database table, this text should be linked to a url stored in the same database. I am trying to do this with preg_replace but I am terrible at it! I keep getting this error: Warning: Wrong parameter count for preg_replace() while($row = mysql_fetch_array( $result )) { $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; echo preg_replace ($reg_exUrl, $row['title'); Any suggestion? Thanks im trying to do a complex(i think) prg replace but i keep getting the error: Code: [Select] Failed evaluating code: $lang->showing-1,1 the code i am trying to replace is: Code: [Select] <asf: lang[showing-<asf: var[num_report_alerts]>,<asf: var[num_report_alerts]>]> and the preg_replace is: Code: [Select] $content = preg_replace('|\<asf: lang\[(.*?)-(.*?)\]\>|e', '$lang->replace_vars($lang->//1, array(\\2))', $content); its supposed to take everything inside <asf: lang[]> and echo \\1 which would be "showing" and then add \\2 into an array which would be "array(1,1)". So the output would be showing 1 of 1. Anyone know where im going wrong? |