PHP - Getting The Value Of A Specified String.
Hi,
Not quite sure how to explain this in technical terms, but basically what I want to be able to do is allow a user to enter a url like: thisurl.co.uk/UF55fg3 And I am then able to retrieve the value "UF55fg3" in the index page. Like the URL shorteners do. Not sure how to do it though. Cheers. Similar TutorialsHi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! I have the following function, which takes a string with commas in it and attempts remove those commas. The way I have it here is that I use explode to take out the commas, which makes an array, and then iterate through that array to put a string back together without the commas. function tags_to_sort_by( $sortMeta ) { $sortByArray = explode(",", $sortMeta); $sortByCount = count($sortByArray); for ($i = 0; $i < $sortByCount; $i++) { $sortByString += $sortByArray[$i]; } return $sortByString; } What does not work is the following line: $sortByString += $sortByArray[$i]; Somehow that outputs a 0, which I don't understand. It should output something like: arrayItem1 arrayItem2 array3 etc. My question is if there either is an easier way to remove the commas from the original string or what I am doing wrong in this line: $sortByString += $sortByArray[$i]; // I am trying to concatenate each part of the array back into the string. Thanks a lot for help with this! hey guys im trying to find a string inside a string which could be made up of different things eg... {$test}, {$test1}, {$test2} etc (but the varable inside could be called anything hence maybe using regex im not sure?) is this possible?...i hope you guys understand....thanks
In PHP Version 8.0 shows error as : In previous versions of PHP it does not show any error. Please resolve the issue. Hello guys i am trying to figure out how to fwrite a string for example "Recommended Settings for Service Pack" under "Current Settings for Service Pack: 5.1.2600ServicePack3Build2600". I figure i cant use line number as an argument because the file report may be dynamic so i will need to use Current Settings as an argument. Please guide me if you have any ideas..thanks:) ! auditreport table ServicePackSetting Service Pack Requirement: Fail Current Settings for Service Pack: 5.1.2600ServicePack3Build2600 MajorAuditandAccountPolicies Maximum Password Age Requirement: Fail Current Settings for Maximum Password Age Requirement: 42 Minimum Password Length: Fail Current Settings for Minimum Password Length Requirement: 0 Ok... I had typed this post out ONCE already and when I clicked REFRESH IMAGE to get a diff captcha it ERASED MY POST LMAO this is not my night.... What I need help with is probably more simple then I can even think right now - ive been digging at this for 3 hrs now and im out of time for the night I have a DB Record storing ID's between PIPES | when the initial entry is made in DB it stores it like so |47| NOTE: the number could be different these are ID's number doesnt matter its just between Pipes When the second entry is added its added like so |47||67| say we have a total of 5 Entries |47||67||82||55||69| I need to find ID 82 in that string and it has to be between Pipes Find 82 in data between | and return that ID 82 I am putting between pipes because the ID's can be duplicate digits in different lengths so say I have 8 as my ID and down the string i have another id as 88 -- I cant possibly find the correct ID without some sort of seperation character so i used Pipes soo my end goal is the ability to search and if true or false do action if ($result == $find_id){ echo "ID is there"; }else{ echo "NOT THERE -- Adding it"; } Any help is appreciated guys Thanks SangrelX I am looking for a date within larger string, lets say the date is December 4, 2010. To find it I use pattern and function below: $Pattern='/[(January|February|March|April|May|June|July|August|September|October|November|December)] \d, \d\d\d\d/i'; preg_match_all($Pattern, $String, $Matches, PREG_OFFSET_CAPTURE, $NumberPosition); The function finds the dates within the string but to my supprise the result I get in $Matches is: r 4, 2010 What I would like to get is: December 4, 2010 but don't know how it should be fixed. I thought that with the pattern I am using but obviously that is not the case. I need to know if a string exists within a string. I've tried using STRIPOS() but it returns zero or false if what I'm looking for is the first part of the string. I don't care what function I use, but I need to get a "true" when the needle string is present anywhere in the haystack string, even at location zero. Is there some way to set up the STRIPOS() statement? I've tried: if ((stripos($title, 'needle') > 0 ) if ((stripos($title, 'needle') = true ) and even if ((stripos($title, 'needle') >= 0 ) which returns true for everything, even when the needle string is NOT present. Any help appreciated. thanks, Tom hey guys just a simple one...im trying to replace {$name} but i dont think ive got the right prefix in the str_replace function...if anyone could tell me where i am going wrong please $content = str_replace("{/$".$variable."}", $value, $content); {$name} Given a text value $path, I want to return the actual path. One option is a switch statement as shown below. Another option is put them in an associated array (or maybe a static array?) and check if the element is set and if not throw an deception. Or maybe a totally different solution. Is one solution better (i.e. more efficient) than another? I will probably be retrieving a path around 5 times for every server hit. Thanks
function getPath($path) { switch($path){ case 'classes': $path=__DIR__;break; case 'application': $path=dirname(__DIR__);break; case 'root': $path=dirname(dirname(__DIR__));break; case 'twig': $path=dirname(dirname(__DIR__)).'/vendor/autoload.php';break; case 'lib': $path=dirname(__DIR__).'/lib';break; case 'help': $path=dirname(__DIR__).'/lib/help'; case 'templates': $path=dirname(__DIR__).'/lib/templates'; case 'htdocs_base': $path=dirname(dirname(__DIR__)).'/html'; case 'resources_base': $path=dirname(dirname(__DIR__)).'/user_resources'; // About 10 more default: throw new Exception("Path {$path} not valid."); } return $path; } I'm trying to do some regex, but I'm having trouble with my input string for the regex. I'm querying a server and getting results from that via socket and trying to regex the results and extract content. I've got the regex working (thanks to mjdamato ), but it only works when I have the regex string like this: $input = "hostname: Hooter's GG 5.1 Elimination HLstatsX:CE version : 1.0.0.58/15 4426 secure udp/ip : 25.2.132.39:27015 map : fy_dustdm at: 0 x, 0 y, 0 z players : 0 (20 max) # userid name uniqueid connected ping loss state adr "; When I get the results from my socket it's stored in a variable and it doesn't work when it's exactly the same. I did var_dump on the results from the socket and this is what it outputs: string(229) "hostname: Hooter's GG 5.1 Elimination HLstatsX:CE version : 1.0.0.58/15 4426 secure udp/ip : 25.2.132.39:27015 map : fy_dustdm at: 0 x, 0 y, 0 z players : 0 (20 max) # userid name uniqueid connected ping loss state adr " Since it's exactly the same why doesn't the second way work? Let me know if this is too confusing.. I want to put some PHP code in a string $output. With the string I create a new php file and in there has to be some PHP code in that file. But... I get error, even on the simpelst code $output = "<?php if(isset($_POST['Bijwerken'])) { header ('Location: http://localhost/Perfect/creategallery.php/creategallery.php'); exit; } ?>"; Gives: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/Perfect/creategallery.php on line 7 What the problem? I have a basic contact us form that gets data from another page if there is and leaves the textarea empty if there is none.
HTML:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" autocomplete="on"> <div class="ui-contact-form "> <span class="icon-user ui-contact-icons"></span><label>Name: </label><input class="input-name" type="text" name="name" autofocus/> </div> <div class="ui-contact-form"> <span class="icon-list ui-contact-icons"></span><span>Service of Enquiry: </span> <div id="radio" class="btngrp-service" name="btngrp-service1" > <input type="radio" id="radio1" name="btngrp-service" value=1><label for="radio1" class="btngrp-service">Moving</label> <input type="radio" id="radio2" name="btngrp-service" value=2 checked="checked"><label for="radio2" class="btngrp-service">Delivery</label> <input type="radio" id="radio3" name="btngrp-service" value=3><label for="radio3" class="btngrp-service">Accounting</label> <input type="radio" id="radio4" name="btngrp-service" value=4><label for="radio4" class="btngrp-service">IT</label> <input type="radio" id="radio5" name="btngrp-service" value=5><label for="radio5" class="btngrp-service">Others</label> </div> </div> <div class="ui-contact-form"> <span class="icon-envelop ui-contact-icons"></span><label>E-Mail: </label><input type="email" name="email" /> </div> <div class="ui-contact-form"> <span class="icon-phone ui-contact-icons"></span><label>Contact No.: </label><input type="tel" name="contactno" /> </div> <div class="ui-contact-form"> <span class="icon-info ui-contact-icons"></span><label>Feedback / Enquiries </label><textarea rows="5" cols="10" name="enquiry" placeholder="Enter your questions here!" ><?php echo htmlspecialchars($enqContent); ?></textarea> </div> <input type="submit"/> </form> if (isset($_GET['delSpeed']) && isset($_GET['delWeight'])) { $delSpeed = $_GET['delSpeed']; $delWeight = $_GET['delWeight']; $enqContent = 'I would like to enquire about a delivery order weighing '; $enqContent.= $delWeight .'KG and would require '.$serviceText. ' shipping.'; } else { $enqContent = ''; }And I validate the other fields making sure the user has entered something and not left it empty $nameErr = $emailErr = $contactErr = $enquiryErr = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { $valid = true; var_dump($enqContent); <-- already cut off here if (empty($_POST["name"])) { $nameErr = "<span>Please enter a valid name</span>"; $valid = false; } else { $name = $_POST["name"]; $_SESSION['name']=$name; } if (empty($_POST["email"])) { $nameErr = "<span>Please enter a valid email</span>"; $valid = false; $emailErr = "Missing"; } else { $email = $_POST["email"]; $_SESSION['email'] = $email; } if (empty($_POST["contactno"])) { $nameErr = "<span>Please enter a valid contact number.</span>"; $valid = false; $error = "error"; } else { $contactNum = $_POST['contactno']; $_SESSION['contactno'] = $contactNum; } if(empty($_POST['enquiry'])) { $nameErr = "<span>Please enter valid content to help us serve you better.</span>"; } else { $enquiry = $_POST['enquiry']; //$_SESSION['enquiry'] = $enquiry; var_dump($enquiry); } if($valid) { //trim input print_r($_POST); $serviceType = $_POST['btngrp-service']; $_SESSION['btngrp-service'] = $serviceType; //header('Location: http://localhost/ppsv2/submit.php'); }As you can see after the IF, I check for the input that came from the other page, the string gets cut off and I have no idea why. When I press submit to check what string I get from $enqContent, this is what I get. I have tried bumping up max_input_vars and post_max_size and nothing seems to work. I would like to enquire about a delivery order weighing 12KG and would%.I would like to know what is causing this and what is the solution to it. Thanks! I am trying to get a <br> to come before Code: [Select] if ($r['othr_pet']) $string .= $r['othr_Pet_txt'];So that if the string has something in it, it will properly break before as like the Cat & Fish Code: [Select] while($r = mysql_fetch_array($sql)) { $string = ""; if ($r['dog']) $string .= "Dog(s) "; if ($r['cat']) $string .= "<br>Cat(s) "; if ($r['fish']) $string .= "<br>Fish(s) "; if ($r['othr_pet']) $string .= $r['othr_Pet_txt']; echo " $string "; } // END While The out come I am looking for is to Hello, i have this type of link: http://www.example.com/cat/name-of-article/5054673 and i want to transform it into: http://www.example.com/cat/name-of-article/full_screen/5054673 i think it can be done with explode or str_replace but i had no luck. Any advise? Thank you Hi, I'm trying to figure out how to get some numbers out of a string. Example of strings $string1 = "3-tech"; $string2 = "109-bobby"; $string3 = "4-Charlie1994"; $string4 = "55-Mr-Smith"; What I want to do is grab everything BEFORE the "-" and the first dash. I'm having a brain meltdown atm and just can't figure it out, I know it's something simple. |