PHP - Line Feed, Carrige Return? Configuration Problem?
Hey Guys,
First Post! Yay I have a problemo, I feel really stupid about having to ask this question. But basically I can't get a new line when I echo output in a script I am writing for my website. Here is the code: echo $newsentry; echo '_______ Read More..'; I tried '\n' I tried using " (double quotes) I have used ' (single quotes) I have positioned the Line Feed '\n' at the begining of an output, and at the end. Neither made any difference. I tried using carriage return '\r' too. Nothing. I haven't coded in PHP for a while, well nothing basic (I know that sounds rediculas but it has been mostly Apps etc, Client Scripts blah blah blah, but I haven't had to echo with a new line for a few years. Probably the last website which I wrote with my friend. So I checked the PHP manual, and I am clearly missing something when I am reading it, I understood it to mean (which as you can see from my code, is what I am currently doing), that you could just somehow type: echo "some string and it carries on to the second line"; However as I first thought, this makes no difference. Could this be a configuration on the Box that hosts this Site?? Sorry for sounding so stupid guys, I appreciate your help. -Craig Similar Tutorialswhat im trying to do is take a youtube embed code find the URL code for that video and remove all other parts of the code keeping only the URL of the video after i get the URL by it self then replace the http://www.youtube.com/ part of the URL with http://i2.ytimg.com/vi/ to do this i know that i need something like this to get the URL of the video http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+) but how to only return just the URL is something idk how to do then use str_replace http://www.youtube.com/(?:v|cp)/" with http://i2.ytimg.com/vi/ so in the end im asking if anyone know how to remove all other codes i dont want and only keep the URL this may have to be done using "regex" im not sure as i dont know to much about regex and what it can do but does sound like it would help lol Hello. Trying to get rid a line feed which is coming from a excel cell which has Text and a line feed after that word. After the excel file has been saved-as tab-delimited, that text transforms to this: "Text" That line feed is between t and the last double-quote. Hex viewer shows: 22 54 65 78 74 0A 22 so it must be that 0A. I have tried with trim() and with str_replace("\x0A","",$data) but nothing (like \r or \n) works. How do I get rid of that hidden character? Is that \x0A correct? Hi there,
I am trying to wrap some content in a div, but when I render it, it is outputting the actual HTML. This is the line I have: add_filter( 'woocommerce_product_description_heading', 'rename_product_description_heading', 10, 1 ); function rename_product_description_heading( $heading ) { return __( '<div class="myclass">Additional Information</div>', 'woocommerce' ); }
which is outputting: <div class="myclass">Additional Information</div> rather than wrapping it in the div.
Can anyone help me with wrapping the "Additional Information" text in a div? Thank you :) I am trying to troubleshoot a problem with a php script that incorporates an RSS feed (with Magpie 0.72.) I did not code the site, and am trying to retrace the original logic. Tech support at my web hosting firm said that the problem was in line 4 of INDEX.PHP: 1. <?php 2. require ("\\\\(HOSTING SITE NAME)\\config.inc.php"); 3. require ($CONFIG['admin_dir'].'page.class.php'); 4. require ($CONFIG['admin_dir'].'function.inc.php'); 5. $currentFile = $_SERVER["SCRIPT_NAME"]; 6. $parts = explode('/', $currentFile); 7. $currentFile = $parts[count($parts) - 1]; 8. $currentFile = preg_replace("/\.\w+$/", "", $currentFile); 9. $page = new page($currentFile, $CONFIG); 10. if ( !$page->isActive() ) { a. $currentFile = $CONFIG['404_page']; b. $page = new page($currentFile, $CONFIG); 11. } 12. require ($CONFIG['include_dir'].$page->getTemplate().'.php'); 13. ?> The RSS feed is in an INCLUDES directory that is defined by CONFIG.INC.PHP: <?php # URL to the RSS feed // CIO.com $FEED_URL = "http://feeds.cio.com/cio/feed/articles?format=rss"; $NUM_ITEMS = 5; require($CONFIG['include_dir'].'magpierss-0.72\rss_fetch.inc'); # Fetch the feed error_reporting(E_ERROR); $rss = fetch_rss($FEED_URL); if($rss) { # Split array with our amount of items $items = array_slice($rss->items, 0, $NUM_ITEMS); $rssChannelTitle = $rss->channel['title']; $rssChannelLink = $rss->channel['link']; // $rssChannelDesc = $rss->channel['description']; $output = ""; $output .= ""; foreach ( $items as $item ) { $output .= '<li class="item">'; $output .= '<a class="itemLink" target="blank" href="'; $output .= $item['link'] . '">'; $output .= $item['title']; $output .= '</a>'; /* CIO's feed contains ads. $output .= '<p class="description">' . $item['description'] . '</p>'; */ $output .= "</li>"; } $output .= ""; } ?> <?php if($rss) { ?> <div class="rssFeed <?php echo $rssChannelTitle ?>"> <h1> <a href="<?php echo $rssChannelLink ?>"> <?php echo $rssChannelTitle ?> </a> </h1> <!-- <h2><?php echo $rssChannelDesc ?></h2> --> <ul class="itemList"> <?php echo $output ?> </ul> </div> <?php } ?> What am I missing? Greetings. First time poster looking for some PHP help if it can be provided, because I'm confused as hell. First off, I'll explain my situation. I'm the IT technician of a small business tasked with ensuring the business' computers and website are running in top shape. I originally joined as a Data Entry clerk to post products to the business' website, but got promoted when they original IT technician left town to pursue his PhD. Before he left, he taught me a few things to prepare watching over the website as my new duty, including some PHP and MySQL. Now, a few months after he's left, I have the glorious task of trying to move our website to a new host because we've apparently outgrown our original host's capabilities. And being based on PHP with a MySQL database, it's turning out to be OH-so-fun. So far, I've managed to download our entire website from the old host and given it to our new host to put up as a testing site, to ensure everything works before we switch hosts. And for the most part, a lot of it has come together nicely, but there's still work needed to be done. And thus we come to the problem I hope someone here can help with. Our website has two back-end Admin sections, an older one that used to handle everything, and a newer one that's sleeker but still reads off a lot of data from the older one to work properly. Normally, when you access those sections, you need to log in first. Now, in the testing site, when I access those areas, the header of each of those sections now reads <?= $row[title] ?> and if I attempt to log in as normal, it just flashes back to the login page with the fields now cleared of what I typed in. When I asked about this to see what the problem might be, the new host said it might "at least two misconfigurations on the new server relative to the old server". So, I've been trying to Google for some help with PHP Configuration Functions, but I don't know if what I'm reading will help me fix the problem. Would anyone here happen to know what they might mean in this case, because my knowledge of PHP is fairly limited beyond what I was taught to keep the website in order without considering a host change... Thanks to those who help or can direct me to a place that helps! Dear All, Hi Guys, I'm a bit new to php coding, so dont really know what the best way to code this up. I want to make a router configuration page, such as it shows the link status (ip/gatewatway etc) and also have input selections such as to turn on/off wifi / dhcp etc. Ideally I would like the data stored and written to a text file as the php server is running on a linux arm embedded system. At present I have been able to read back from a text file the corresponding values for each of the status information (these are stored on a seperate line), but I'm having difficulty writing and reading the input selection boxes, such as when the dhcp is disabled I need it to write to a file that its been disabled and refresh the page to allow entry of the static ip box and then when the apply button is pressed the value is written to the file. This may be out of my depth, hopefully someone could give me some pointers. I feel that the text file might not be the best way of storing and recalling values but I don't know of another way. Many Thanks Tim Hi ,
My site gives a blank page when i click on an article due to insufficient memory. I tried making changes to the php.ini file but the changes are not getting reflected.
Please advice if a server restart is needed for this, how do i go about it?
Thanks in advance
Every now and then, I experience some strange behavior and eventually trace it back to parse_ini_file's scanner_mode being applicable to some parameter but not another, and am looking for alternatives. Below are several of my thoughts. How do you store configuration settings? Do you use different approaches based on the application, and if so what criteria governs which you use? Keep with a ini file with parse_ini_file. Obviously, not working for me. An ini file but with a class dedicated to ensuring the data is appropriate. Seems like too much duplicating content which will result in errors. YAML. Don't think I want to. XML. Not as readable. In a database. Maybe, but might be harder to manage. Hardcode an array in PHP. Probably not. JSON. I like the idea, but feel comments are important in a config file, and am considering the following: Add extra valid JSON properties which contain comments. Don't like the idea. Use JavaScript's JSON.stringify. Too much mixing technologies. Add comments to the JSON and then strip them using a 3rd party parser such as https://json5.org/ or a little regex. My main issue is inability to auto-format, but this seems viable. Any other ideas?Thanks!
hi, i have a configuration file with this content for example: test = "100"; teste2 = "300"; now need change the test from 100 to 300, i just want use something like this: function ( "test" , 300 ); how can i do that? thanks for help Does any know how to set SMTP Mail Configuration using the gmail account? I have a configuration file, and I use parse_ini_file() to parse it into an array at the initial entry point of my script.
I would like the settings to be available to all downstream scripts/methods/functions. Note that my intent is not to change them outside of the configuration file, and ideally they will be readonly, however, if not, I suppose that is okay and I will just be sure not to modify them.
I've read about dependency injection, and while this mostly makes sense, it seems like a lot of script/troubleshooting for little if any value for this scenario.
I've read that global variables are bad (couples your objects to some "god" object, cannot unit test, difficult to troubleshoot, difficult to work with multiple developers, potential conflicts with other classes, namespace pollution), but maybe not for this case?
Another option is defining a bunch of constants to the appropriate values, but this seems redundant.
Or maybe some static class with all the values?
What would be the best way to make configuration settings available to all PHP scripts, functions, and methods? Hi, I've been googling for a while now for an example of how to read, edit and write a configuration file. This part was easy to find... <?php $icon_settings = parse_ini_file("test.desktop"); print_r($icon_settings); ?> ...the above code works great, but how do I edit and write back a configuration file like this... Code: [Select] #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Name=Firefox Web Browser Comment=Browse the World Wide Web GenericName=Web Browser Exec=firefox %u Terminal=false X-MultipleArgs=false Type=Application Icon=firefox # ... and so on back to the drive? Thanks. Hi, I don't know if this is even possible, but I need to copy configuration of existing server to my localhost (using XAMPP on windows). I only have full output of phpinfo() function from that server (I don't have access to php.ini), and I would like to change my localhost server to behave exactly like remote one.
Is this even possible? This topic has been moved to PHP Installation & Configuration. http://www.phpfreaks.com/forums/index.php?topic=326567.0 Hi all, I have a lot of images in a directory called image1.jpg image1_thumb.jpg image2.jpg etc.. When I use this code foreach (glob('./aircraft/' . $_GET['reg'] . '*.jpg') as $file) The foreach statement gets the _thumb.jpg images - I am trying to just get the images without _thumb.jpg at the end. What is wrong with it? I am guessing it is the *.jpg but I have tried taking that out and the script then does not work. Thanks for your help. Its an easy script But im not smart enough to fix it here is the code: aanmelden(php) Code: [Select] <?php include("config.php"); if(!empty($_POST)) { if(!preg_match('/^[A-Za-z1-9-]{'.$Minimale_Wachtwoord_Karakters.',}$/', $_POST['gebruikersnaam'])) { $error = $error+1; echo "Je gebruikersnaam moet minimaal 3 tekens bevaten en mag geen komma of andere onbedoelde tekens zijn<br>Toegestaan is <br>A t/m Z <br>a t/m z <br>1 t/m 9 <br>en -"; } else { echo "geldige gebruikersnaam(goedgekeurd)"; } if(preg_match("/^[A-Za-z1-9-]{3,}$/", $_POST['wachtwoord']) && preg_match("/^[A-Za-z1-9-]{3,}$/", $_POST['herhaalwachtwoord'])) { if($_POST['wachtwoord'] != $_POST['herhaalwachtwoord']) { $error = $error+1; echo "niet hetzelfde wachtwoord"; } else { echo "hetzelfde wachtwoord (goedgekeurd)"; } } else { $error = $error+1; echo "wachtwoord moet minimaal 3 tekens bevatten!"; } if(!preg_match("/^[A-Za-z1-9_.-]{1,}@[A-Za-z1-9-]{1,}\.[A-Za-z1-9]{2,3}$/", $_POST['email'])) { $error = $error+1; echo "onjuiste email"; } else { echo "goedgekeurd!"; } if(!isset($error) { echo "goedgedaan geen errors!"; } } else { ?> <HTML> <HEAD> <TITLE>New Document</TITLE> </HEAD> <BODY> <form method="post"> <input type="text" name="gebruikersnaam" value="gebruikersnaam" maxlength="20" size="20"> <input type="password" name="wachtwoord" value="wachtwoord" maxlength="20" size="20"> <input type="password" name="herhaalwachtwoord" value="herhaalwachtwoord" maxlength="20" size="20"> <input type="text" name="email" value="voorbeeld@domeinnaam.extensie" maxlength="50" size="20"> <input type="submit" name="login" value="inloggen"> </form> </BODY> </HTML> <?php } ?> config(php) Code: [Select] <?php $Minimale_Wachtwoord_Karakters = 3; ?> Can anyone tell me what's wrong with this particular part of my php code? $handle = fopen(''lovell.txt, ''a''); That was the line it said there was an issue with, and I'm new and can't seem to figure it out. Hi. I want a simple textbox, that when submited, will replace very every new line, with the <br> tag. What will happen, when it submits, it will take the contents of a textbox, add the <br> tag where a new line is suposed to be, and save the string to a MySQL Database. I think this is the easiest way of allowing a user to edit what appears on a website when logged in, but if there is a easier way, then please tell me. What I am trying to do, is a login page, and once logged in, you enter new text into the textbox, click submit, and on the website homepage, the main text will change to what was submitted. But if there is a new line, I think the only way in HTML to make one is to put a <br> tag, so I want the PHP to but that tag wherever there is a new line. Sorry if I am confusing, I am not that advanced at PHP, but I would be very happy if you could supply me with the correct code. Time is running out... If you do not understand me, please tell me -- PHPLeader (not) i have to read a single line from a csv, its a really big file and i only need one column.
i need the response to be a string ,i made a search and found the following code but i dont have any idea how to get a single line from a single string per run .
<?php $row = 1; //open the file if (($handle = fopen("file.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 0, ",")) !== FALSE) { $num = count($data); echo "<p> $num fields in line $row: <br /></p>\n"; $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } } fclose($handle); } ?> Edited by bores_escalovsk, 16 May 2014 - 06:38 PM. |