Replacement for writing out entire domain? - php

I am in the process of creating a website that will eventually be moved to a different domain. Every link on the site currently starts with http://www.mydomain.com/folder. This means that when I move domain I will have to change each and every link. Is there a replacing method of this? Sorry that this is a very basic question, I wasn't quite sure what I was looking for. Thanks for any help.

Firstly; best way is to make it configurable. There should be a global variable:
HTTP_SERVER = 'http://www.mydomain.com/';
and when you want you build a link, you should use:
Link To Folder
But let's get back to your question;
You can use an IDE to search and replace in all of the files in a specific folder. I use Visual Studio which you can choose to search in entire project and replace. But if you want other quick solutions, the best one comes to my mind is Notepad++, you can open a bunch of files and search & replace among them. Another one is Sublime Text which is a great lightweight text-editor / IDE that i use.

I would use an IDE to do a global search and replace across all files in the project.

try declaring a $base_url="www.domain.com/folder" in your connection file which will be included in all pages. so that you can just change the base url there only. and when you want the link call it as $base_url.'/page_name.php';

Related

How to find all files with a function in phpstorm?

How I can find and show all files in Phpstorm where this method
$this->other_model->any_method()
is called?
cmd+shift+f for Mac and ctrl+shift+f for Windows will find any piece of text throughout the project or directory. Or you could use alt+f7 to find usages.
PHPStorm Keyboard Mapping.
Viewing Structure of a Source File.
You can search for symbol with combination Ctrl+Shift+Alt+N. This combination allows you to search not only PHP classes/methods but also PHP variables, CSS classes etc.
If you want to find method usages in files:
click on your method and press Alt+F7
If you want to search any composition of your desire search, you can use from searching everywhere. I prefer to use this because PhpStorm makes it possible to look for any item of the source code, databases, actions, elements of the user interface, etc. in a single action.
to use that, only press search button in the right upper corner of phpStorm or 2 times press shift key on your keyboard. Now you can find your search everywhere. This is great functionality of phpStorm.
To read more information about using this search method, go to the following link:
Searching Everywhere
To See all the methods for search in phpStorm, Go to the following link:Searching Through the Source Code

Query about template style of site being used in php

One of my client sent zip file today, which contains website source code, he is developing.
When i opened "template" folder and "template-comments.html" file.
I saw some "variable" being used there with % arround it.
One of line is :-
<title>%title%</title>
Whole template folder is filled with such files. I am just not sure, how it has been done. Yes, I know you might be thinking, what a lame programmer i am. I am working for client, and i am just not sure, what his file mean.
I am good(not best) in PHP. I have developed custom e-commerce webapplication using phpfastcache and all. But, I have never experienced such coding style in my life.
I beg my pardon for my lame question, but i am seriously not aware of such coding style and i am eager to know.
Most Important: Whole website doesnot use any PHP framework.
Can anyone help me understand such coding style.
If i am unclear on any part. Kindly ask, But i am desperate to learn this.
Note: These are not placeholder, but these style is being used in running website. Here is image link, I have removed few info just to keep privacy.
Thanks
Update: I got the answer.
Person is first using file_get_contents from something.php for getting info from file "something.html" and than using str_replace function to replace the actual link with placeholder.
Thanks
There are some Template Engines that replace those placeholder for values that you specified, the syntax of the placeholder can vary depending on the Template Engine. As example take a look at Smarty and its syntax.
<title>{title}</title>
Conclusion, he maybe using a Template Engine.

How to copy a complete php/mysql website with php?

I have a typo3 website with no user genrated or dynamic content.
So it is unnecessary to use php and the database.
Is it possible (with php) to clone the hole website and store every page as an html page?
I have only a normal webspace, so i cant install tools like "eAccelerator".
My idea:
- grab every link from the sitemap
- file_get_contents -> store as html
But i think this is not a clean solution? Or?
Thanks in advance!
james
you can use a simple software called HTTRACK., here is the link:
httrack.com
Why you need to use php to copy it? Did you consider using a command line tool like wget? wget allows you to create an "offline" copy of a website which you can of course host somewhere else. Sounds to me exactly like the thing you want to do.
In case you are really stucked to php, you will need an HttpRequest, call the site, parse all links and resources, download the resources, follow the links and do the same again. This is the most simple solution, without any checking for conflicting resources or other stuff which could go wrong.
Sitesucker http://sitesucker.us is an excellent tool you can run from any mac. It works very well, I use it all the time.
But don't forget that by creating a static copy of your site, you will lose your templating functionality. So if you really want to make your website static, I strongly recommend to - at least - put the identical parts of each page into php-includes. Mostly head, page header, footer, navigation. So you're ready for future changes.
If it's just because your TYPO3 is too slow, look at the nc_staticfilecache extension which can speed it up very well.
Using TYPO3 where you need just a simple HTML is a huge overflow, invest in DreamWeaver and code all things 'manually'.

Best method to replicate a website

I have recently created a directory for a customer of mine. The website is complete however he wants a replicated version of the website so he can test the website and learn how to use it.
To replicate his website fully it will take hours as I will have to change every hyperlink and URL in the website.
As my customer is being a little pushy and wants it done quickly I was wondering if it is posible to create a test website and add a little javascript that will replace his URL each time (until I create a full testing solution?).
For example if it was:
Test
it would replace it to:
Is this posible?
Is it recommended for the time being, until I create a full test solution?
You really should use relative paths so the files interact in relation to each other, regardless of where the files live.
That said, here is a possible quick JS solution you can use for the time being while you make your links relative instead of absolute:
$("a").each(function() {
var href = this.href;
href = href.replace("mydomain.com/", "mydomain.com/test/");
this.href = href;
});
Open up the site files in Notepad++ or any editor that supports file replacement, then do a replace through files (N++ will do this automatically for you), replacing the live URL with a config variable, then set the URL variable as desired for the test site.
Now you have a config variable for the URL, it will be easy if the client wants to change domain or you want to deploy elsewhere.
It is certainly possible to sort out your hyperlinks with javascript, specifically it would be really easy with a framework like jQuery.
$('a').each(Function(e){
e.attr('href', e.attr('href').replace(/http:\/\/mainsite.com/gi, 'http://newsite.com'));
});
Hopefully the URLs in your css files, link hrefs and so on would be relative, otherwise you would need to change those too. At this point a php solution would be more appropriate.
The wget command-line utility has a --convert-links option. If you download a web site using that option, wget will convert the links in such a way that "local browsing works reliably."

Is there a way to setup your own source tools on eclipse?

I'm not sure source tools is the right way to define what I mean so I'll give you an example.
In my code I may have something like that
<div>
<span>Hello</span>
</div>
Since I want my app to be translated I use the _ function.
So I would like to be able to select "Hello" and to click somewhere on the context menu to a launch a tools of mine that would change "Hello" to <?=_("Hello");?>
What you are looking for are regular expressions.
Eclipse has some awesome search and replace functionality.
Do a project wide file search on *.html files with the regexp >([^<]+)< and then replace with ><?=_("$1");?>
Afterwards you can mark which replacements should actually take place.
It might not get you all the way, but it sure is going to help with the bulk of it.

Categories