Jump to content

Search the Community

Showing results for tags 'string'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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 (PhpStorm, VS Code, 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I am trying to write post variables to a csv file but it writes everything in one line separated by comma <?php $list= array($_POST['purchases']); $file = fopen("purchases.csv", "w"); foreach ($list as $line) { fputcsv($file, $line); } fclose($file); ?> Result in purchases.csv file Marilyn,Nancy,Johan,Carol,Juanic,Shirley But I want every string value on separated line Marilyn Nancy Johan Carol Juanic Shirley
  2. For right or wrong, I've been using XML to define my Doctrine entities. When the XML changes, my entities need to change. I've automated the process with a simple PHP script which allows me to swap some text to modify one of the auto-generated methods, add methods, etc. Kind of clunky but it works well enough. Now, I recently had the need to remove a given method in its entirety from a given class. I "could" just add the entire string which represents the method name, earlier comments, and script for the method to my parsing script to my parsing script and remove it, but would like to be a little more concise. For instance, say I have $script as follows: $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get foos. * * @return \Doctrine\Common\Collections\Collection */ public function getFoos() { return $this->foos; } /** * Get somethingElse. * */ //... more stuff below } EOT; How would you recommend creating the function: removeFunction($script, 'getFoos') which would remove the given function along with its comments from the $script string and result with? $script = <<<'EOT' class SomeEntityClass { //... more stuff above public function getSomething() { return $this->something; } /** * Get somethingElse. * */ //... more stuff below } EOT; Assuming regex is the way to go, I was thinking of something like the following, but could use some help with the regex expression. function removeFunction($script, $method) { $method="public function $method("; //regex to remove script with which starts after pattern "{\n" OR "**/", contains $method, and is located before pattern "\n{" OR "\n /**" return $script; } Thanks
  3. Below I have "Input" where it shows the original string. Basically I want to remove everything before " - ". I would like to know how can I get the "Output" results using PHP? Input $variable_1 = Lulu-free - Swimsuit swimwear red $variable_2 = Pap & Jones - Bard Mini Dress Output $variable_1 = Swimsuit swimwear red $Variable_2 = Bard Mini Dress
  4. Hello. Just a quick question about using a loop to create a string from post variables that will then be used in a query. I have several post variables submitted in a form, some of which contain a value of T. Others are not selected. In the database there are several columns which may contain values of T or may not. I would like to construct a query that searches for specific columns containing T and ignoring the rest. I'm using WHERE "T" IN(colnames). I need to get the column names into a comma separated string. Here's what I'm using: $postVal = array("1", "2", "3", "4", "5"); foreach ($postVal as $key=>$val){ $newVar = “col”.$val; if ($$newVar == "T") { *create/add to comma-separated string } else { *ignore } } I hope that seems clear enough. I'm just not sure if I'm on the right track or not. What do you think? Thank you, in advance!
  5. i need to change the color of a word in a string where the word is unknown (from $_POST) and may have one or more uppercase chars. code please.
  6. I have a string e.g. products.0.name and I want to change the string to; products[0][name] I have come up with some code that works but is a bit of a hack, my code is below; var array = field.split("."); field = array[0]+'['+array[1]+']['+array[2]+']'; Is there a better way, I am sure there is using regex? Thanks
  7. I am using AJAX to send an array of values to a PHP page that will insert the data into MySQL database. For some reason only the last 5 values are inserted into the MySQL database and I am woundering how to fix that. I am using foreach loop. AJAX Request: Array: [".testimonial", 1119, 316, 1663, 608, "#header", 723, 66, 1663, 608] Posting the array: Sending Array Parameters using " ; " to split. clicks .testimonial;1119;316;1663;608;#header;723;66;1663;608 Source Sent: clicks=.testimonial%3B1119%3B316%3B1663%3B608%3B%23header%3B723%3B66%3B1663%3B608 PHP Page <?php $clicks = $_GET["clicks"]; $clickArray = explode(";",$clicks); $arrays = array_chunk($clickArray, 5); $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "clickmap"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $keys = array('postIdentifier', 'postPos_x', 'postPos_y','postWindowWidth','postWindowHeight'); foreach ($arrays as $array_num => $array) { $values = array(); foreach ($array as $item_num => $item) { $values[] = $item; } $data = array_combine($keys, $values); extract($data); // now your variables are declared with the right values http://php.net/manual/en/function.extract.php $sql = "INSERT INTO data (user_id, identifier_name, pos_x, pos_y, window_width, window_height, status) VALUES ('1', '$postIdentifier', '$postPos_x', '$postPos_y','$postWindowWidth','$postWindowHeight', 'ok')"; } if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> Is this the correct way of coding it, and why does it post only the last 5 values? Any help would be much appreciated!
  8. Hi dear php coders! ]'m almost new in php and now i'm dealing with wordpress . ] want to get a long string from database with get_post_meta function. (and aftar that i wanna Parse this string and Play with that ...! ) how can i do that ?? i don't know what arguments i must pass to the function ... any help would be appreciated. thanks in advance.
  9. Hello. I have a problem when I send an article to DB from the server (in localhost everything is working fine). So, the news_post (textarea) is sending backslashes before single and double quotes, broking embed elements (images, videos, etc.). The articles are sent to DB throught this coide:
  10. Hello guys! For every word in a sentence or phrase how do i make the first letter for each word a capital letter. Expecting your response Thanks guys!
  11. Hey friends, I just started learning php. I want to know the difference between == and === I exactly want to know the comment section of the given code below. Thanks. <?php $mystring = 'abc'; $findme = 'a'; $pos = strpos($mystring, $findme); // The !== operator can also be used. Using != would not work as expected // because the position of 'a' is 0. The statement (0 != false) evaluates // to false. if ($pos !== false) { echo "The string '$findme' was found in the string '$mystring'"; echo " and exists at position $pos"; } else { echo "The string '$findme' was not found in the string '$mystring'"; } ?>
  12. I'm going to create a web page with <iframe> tag & want that the src of <iframe> change as value of url in query string changes.i.e. mysite.com/?url=google.com then,src of <iframe> should google.com
  13. Hi Community! :-) (Sorry for my average english) I recently started coding in php, till now, i allready have advanced skills in programming with C# and thus, had no problems writing my own script. Still, my script does not really work, i'm trying to check if a file contains a md5(string), but the script never finds the string. This is the script: (please don't mind any security issues, this is just a test. But if you have any tips and tricks to improve the security, i'd be glad to receive them) <?php $webname = $_POST["webname"]; $webcode = $_POST["webcode"]; $webpass = $_POST["webpass"]; if (file_exists("web/". $webname . ".html")) { $file = file_get_contents("web/". $webname . ".html", "r"); if (strpos(md5($webpass),$file) !== false) { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<!--- ". md5($webpass) . "--->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } else { echo "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; } } else { $usergen = fopen("web/" . $webname . ".html", "w") or die("Unable to open file!"); fwrite($usergen, $webcode); fwrite($usergen, "<br><!--- ". md5($webpass) . " --->"); fclose($usergen); echo "Generated! You can view your site under /web/" . $webname . ".html"; } echo "<FORM><INPUT Type=\"button\" VALUE=\"Back\" onClick=\"history.go(-1);return true;\"></FORM>"; ?> What it does it pretty simple, you enter some html-code that'll be stored in the "webcode" variable, a password, let's say "apple" in "webpass" and the filename is stored in "webname". On first creation, a html-file is created with the <!--- md5(apple) ---> at it's end, the HTML Tags are needed to hide the string from any visitors. If someone wants to edit the File created before, he also enters "apple". Then the string will be looked up as md5(apple) in the file. If the strings match, it's true and the changes should be saved. Whatever i do, though, i'm allways ending up here if i try to edit an existing file: "The file already exists but you entered the wrong Password.<br> Pressing the \"return\" Button will bring you back without loosing the code you entered."; As i said, i'm a newbie, i'd appreciate any tips and help. Thank you in advance!
  14. Hi I have a MySql database and wondered if there is a code to search a table field with a given string and display the number of unique occurrences. The table is asterisk_cdr and would like to know how many calls received daily on a perticular channel. Thanks shmideo
  15. The situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it. For example: <?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?> This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!)
  16. Hi, I'm trying to make a program that filters data out of a website. Now I've got a problem. For example, I've this line: <td class="maintxt" width="200"><a href="profile.php?x=Stranger">Stranger</a></td><td class="maintxt" width="200">Godfather (96.76%)</td><td class="maintxt" width="200"><i><a href="clanprofile.php?x=Ettertjes">Ettertjes</a></i></td> Form this line I want to set the word "Stranger" in a variable, and do the same for the word "Godfather". What is the best method to do this? Thanks in advance, iRoot121
  17. Overview: Sort unique string from an array and display results into a variable which can be echoed into jQuery to be displayed as a graph. I using Wordpress with a repeater from custom post fields plugin, code below: $repeater = get_field('treatments'); foreach( $repeater as $key => $row ) { column_id[ $key ] = $row['treatment_name']; } array_multisort( $column_id, SORT_ASC, $repeater ); foreach( $repeater as $row ) { print_r($row); } The print_r returns.. Array ( [treatment_name] => back pain [pain_level] => 4 ) Array ( [treatment_name] => back pain [pain_level] => 5 ) Array ( [treatment_name] => back pain [pain_level] => 7 ) Array ( [treatment_name] => back pain [pain_level] => 10 ) Array ( [treatment_name] => shoulder pain [pain_level] => 3 ) Array ( [treatment_name] => shoulder pain [pain_level] => 8 ) Array ( [treatment_name] => shoulder pain [pain_level] => 10 ) I wish to be able to sort the array data into a variable I can using within JS. { treatment: '1', a: 4, b: 3 }, { treatment: '2', a: 5, b: 8 }, { treatment: '3', a: 7, b: 10 }, { treatment: '4', b: 10 }, A = back pain B = shoulder pain [treatment_name] - is a text field, so I looking for every unique [treatment_name] to added for example having one treatment called 'foot ache' with the pain level of 6 would be added to the start of the list as C. e.g. { treatment: '1', a: 4, b: 3, c: 6 }, { treatment: '2', a: 5, b: 8 }, { treatment: '3', a: 7, b: 10 }, { treatment: '4', b: 10 }, I have gone over and over trying to work the logic out but seems my level of php is not up to par, so I thought no better place to asked then the people who got me this far.. Any questions please do let me know, and anyone will to help your a star..
  18. Hi im trying to use the substr function in php. I have a string called $finalString and im trying to grab the last character of that string the line of code im using is : $startIndex = substr($finalString, -1); it wont work giving the error : Warning: substr() expects parameter 2 to be long, string given in /users/2017/bfm3/public_html/cs1109/lab10/markovnew.php on line 34
  19. Hello, i have the following code: php 5, ms server 2008, iis 7 I pass this script a csv list of file paths like so... ,C:\path\path\path\file.name,C:\path\path\anotherFile.name,C:\path\path\path\file3.file (yes there is a leading comma in the string for some reason..) $files = $_POST['files']; $files = explode(',', $files) foreach($files as $filename){ if(file_exists($filename)){ echo '":' . $filename .':"Does Exist<br />'; } else { echo 'Sorry ":' . $filename . ':" Does Not Exist<br />'; } } My problem: the first file path shows it exists and there is no white space in the string, all the file paths after the first one show like such: ":C:\path\path\path\file.name:" Does Exist // 1st path (good) ": C:\path\path\anotherFile.name :" Does Not Exist ": C:\path\path\file3.file:" Does Not Exist pleas note... i put the ": and :" in there to show that there is indeed a white space character in front of and behind the filepaths. EXCEPT for the last path.. there is no trailing white space there. Please explain why you think the white space is being added to these and what i can do to get rid of it. thanks, dogdaynoon
  20. I just found code that does this: orig = orig.replace( "<br>", "<br>" ); orig = orig.replace( "<BR>", "<br>" ); orig = orig.replace( "<bR>", "<br>" ); orig = orig.replace( "<Br>", "<br>" ); I see why it's done this way (to encompass any caps variation on the BR) but since .replace() will only get the first instance, this is just bad all the way around. Also, there's no way to do a toLowerCase() because that will mess up the rest of the string. Is there some sort of JS regex way to replace all instances of <br> regardless of the caps? Thanks!
  21. Hey, I have created a contact us form which works nicely with my site, however I have some backup PHP validation code, which all works apart from the last name section, how can I set it up to it checks to see if there is a first name and a last, maybe even another name? This is what I have so far and it only works if you put in a first name and nothing else: $string_exp = "/^[A-Za-z.'-]+\$/"; if(!preg_match($string_exp, $name)) { $error_message .= 'The Name you entered does not appear to be valid.<br/>'; } Thank you
  22. Very much a noob here...please bear with me! I have a MySQL table that has a particular column that contains data that "looks" like CSV data. Example: We'll say that the column name is "class" record 1 - 1,3,5,2,8,10 record 2 - 6,4,8,10,2,1 I need to read through each record (I know how to do this...) read each field value into a string (can do this...) Here is my challenge: Once I have the data read into a string value I need to be able to "remove" a given value from the string and write it back. In other words, let's assume I want to remove "1": Data would become: record 1 - 3,5,2,8,10 record 2 - 6,4,8,10,2 Note that any of the field values could have a "1" *and* a "10". Simply looking for the "1"s in a string search isn't going to cut it. I am assuming the data needs to be pulled into an array and do some comparing...but my brain is "losing it" here...no clue how to proceed! Can someone point me in a direction?
  23. How can check This String '2013-09-12:14:00:01' is later than 24 hours of current time?
  24. 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
  25. 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
×
×
  • 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.